jbasdf-disguise 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. data/.document +5 -0
  2. data/.gitignore +5 -0
  3. data/LICENSE +20 -0
  4. data/README.rdoc +43 -0
  5. data/Rakefile +93 -0
  6. data/VERSION +1 -0
  7. data/app/controllers/admin/disguise/themes_controller.rb +32 -0
  8. data/app/models/theme.rb +37 -0
  9. data/app/views/admin/themes/_theme.html.erb +7 -0
  10. data/app/views/admin/themes/edit.html.erb +10 -0
  11. data/app/views/admin/themes/no_themes.html.erb +4 -0
  12. data/config/disguise_routes.rb +6 -0
  13. data/db/migrate/20090530170040_create_themes.rb +11 -0
  14. data/disguise.gemspec +163 -0
  15. data/generators/theme/USAGE +13 -0
  16. data/generators/theme/templates/INSTALL +5 -0
  17. data/generators/theme/templates/description.txt +1 -0
  18. data/generators/theme/templates/locales/en.yml +2 -0
  19. data/generators/theme/templates/preview.gif +0 -0
  20. data/generators/theme/templates/stylesheets/styles.css +1 -0
  21. data/generators/theme/templates/views/_footer.html.erb +7 -0
  22. data/generators/theme/templates/views/_head.html.erb +9 -0
  23. data/generators/theme/templates/views/_header.html.erb +28 -0
  24. data/generators/theme/templates/views/application.html.erb +18 -0
  25. data/generators/theme/templates/views/home.html.erb +14 -0
  26. data/generators/theme/theme_generator.rb +43 -0
  27. data/lib/action_controller/disguise_application.rb +50 -0
  28. data/lib/disguise.rb +8 -0
  29. data/lib/disguise/initialize_routes.rb +8 -0
  30. data/lib/disguise/tasks.rb +34 -0
  31. data/locales/ar.yml +8 -0
  32. data/locales/bg.yml +8 -0
  33. data/locales/ca.yml +8 -0
  34. data/locales/cs.yml +8 -0
  35. data/locales/da.yml +8 -0
  36. data/locales/de.yml +8 -0
  37. data/locales/el.yml +8 -0
  38. data/locales/en.yml +7 -0
  39. data/locales/es.yml +8 -0
  40. data/locales/fr.yml +8 -0
  41. data/locales/it.yml +8 -0
  42. data/locales/iw.yml +8 -0
  43. data/locales/ja.yml +8 -0
  44. data/locales/ko.yml +8 -0
  45. data/locales/lt.yml +8 -0
  46. data/locales/lv.yml +8 -0
  47. data/locales/nl.yml +8 -0
  48. data/locales/no.yml +9 -0
  49. data/locales/pl.yml +8 -0
  50. data/locales/pt.yml +8 -0
  51. data/locales/ro.yml +8 -0
  52. data/locales/ru.yml +8 -0
  53. data/locales/sk.yml +8 -0
  54. data/locales/sl.yml +8 -0
  55. data/locales/sr.yml +8 -0
  56. data/locales/sv.yml +8 -0
  57. data/locales/tl.yml +8 -0
  58. data/locales/uk.yml +8 -0
  59. data/locales/vi.yml +8 -0
  60. data/locales/zh-CN.yml +8 -0
  61. data/locales/zh-TW.yml +8 -0
  62. data/locales/zh.yml +8 -0
  63. data/rails/init.rb +3 -0
  64. data/tasks/rails.rake +2 -0
  65. data/test/disguise_test.rb +7 -0
  66. data/test/test_helper.rb +18 -0
  67. metadata +120 -0
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.sw?
2
+ .DS_Store
3
+ coverage
4
+ rdoc
5
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Justin Ball
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,43 @@
1
+ = disguise
2
+
3
+ A simple theme system for your Rails application.
4
+
5
+ == Installation
6
+ sudo gem install disguise
7
+
8
+ == Setup
9
+ Disguise comes with an admin controller to make changing your theme simple. By default it is not protected.
10
+ In order to prevent unauthorized users from changing your theme you can override the admin controller like this:
11
+
12
+ class Admin::ThemesController < Admin::Disguise::ThemesController
13
+ before_filter :login_required
14
+ layout('admin')
15
+ end
16
+
17
+ Also be sure to add a route to the new controller in routes.rb:
18
+
19
+ # admin
20
+ map.namespace :admin do |a|
21
+ a.resource :theme
22
+ end
23
+
24
+ === Rake tasks
25
+
26
+ Add disguise rake tasks to your rails project. Include the following line at the end of your Rakefile:
27
+
28
+ require 'disguise/tasks'
29
+
30
+ Then run the following to add the required files and database migration:
31
+ rake disguise:setup
32
+ rake db:migrate
33
+
34
+
35
+ == Usage
36
+ Generate a new theme for your Rails application using the built in theme generator:
37
+
38
+ ./script/generate theme theme_name
39
+
40
+
41
+ == Copyright
42
+
43
+ Copyright (c) 2009 Justin Ball. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,93 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ begin
6
+ require 'jeweler'
7
+ Jeweler::Tasks.new do |gem|
8
+ gem.name = "disguise"
9
+ gem.summary = "Easy to use view theme system for Rails"
10
+ gem.email = "justinball@gmail.com"
11
+ gem.homepage = "http://github.com/jbasdf/disguise"
12
+ gem.description = "Add themes to your Rails application to easily change the view layer and impress everyone you know"
13
+ gem.authors = ["Justin Ball"]
14
+ gem.rubyforge_project = "disguise"
15
+ gem.files.include %w( tasks/*
16
+ db/migrate/*.rb
17
+ generators/**/**/**/*
18
+ app/**/**/**/*
19
+ config/*
20
+ locales/*
21
+ rails/*
22
+ test/*
23
+ lib/**/* )
24
+ end
25
+ rescue LoadError
26
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
27
+ end
28
+
29
+ # rubyforge tasks
30
+ begin
31
+ require 'rake/contrib/sshpublisher'
32
+ namespace :rubyforge do
33
+
34
+ desc "Release gem and RDoc documentation to RubyForge"
35
+ task :release => ["rubyforge:release:gem", "rubyforge:release:docs"]
36
+
37
+ namespace :release do
38
+ desc "Publish RDoc to RubyForge."
39
+ task :docs => [:rdoc] do
40
+ config = YAML.load(
41
+ File.read(File.expand_path('~/.rubyforge/user-config.yml'))
42
+ )
43
+
44
+ host = "#{config['username']}@rubyforge.org"
45
+ remote_dir = "/var/www/gforge-projects/disguise/"
46
+ local_dir = 'rdoc'
47
+
48
+ Rake::SshDirPublisher.new(host, remote_dir, local_dir).upload
49
+ end
50
+ end
51
+ end
52
+ rescue LoadError
53
+ puts "Rake SshDirPublisher is unavailable or your rubyforge environment is not configured."
54
+ end
55
+
56
+ require 'rake/testtask'
57
+ Rake::TestTask.new(:test) do |test|
58
+ test.libs << 'lib' << 'test'
59
+ test.pattern = 'test/**/*_test.rb'
60
+ test.verbose = true
61
+ end
62
+
63
+ begin
64
+ require 'rcov/rcovtask'
65
+ Rcov::RcovTask.new do |test|
66
+ test.libs << 'test'
67
+ test.pattern = 'test/**/*_test.rb'
68
+ test.verbose = true
69
+ end
70
+ rescue LoadError
71
+ task :rcov do
72
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
73
+ end
74
+ end
75
+
76
+
77
+ task :default => :test
78
+
79
+ require 'rake/rdoctask'
80
+ Rake::RDocTask.new do |rdoc|
81
+ if File.exist?('VERSION.yml')
82
+ config = YAML.load(File.read('VERSION.yml'))
83
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
84
+ else
85
+ version = ""
86
+ end
87
+
88
+ rdoc.rdoc_dir = 'rdoc'
89
+ rdoc.title = "disguise #{version}"
90
+ rdoc.rdoc_files.include('README*')
91
+ rdoc.rdoc_files.include('lib/**/*.rb')
92
+ end
93
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.1
@@ -0,0 +1,32 @@
1
+ class Admin::Disguise::ThemesController < ApplicationController
2
+ unloadable
3
+
4
+ before_filter :get_theme
5
+
6
+ def edit
7
+ @current_theme, @themes = Theme.available_themes(@theme)
8
+ if @themes.empty?
9
+ respond_to do |format|
10
+ format.html { render :template => 'admin/themes/no_themes' }
11
+ end
12
+ else
13
+ respond_to do |format|
14
+ format.html { render :template => 'admin/themes/edit' }
15
+ end
16
+ end
17
+ end
18
+
19
+ def update
20
+ @theme.update_attributes!(params[:theme])
21
+ respond_to do |format|
22
+ flash[:notice] = t('disguise.theme_updated')
23
+ format.html { redirect_to edit_admin_theme_path }
24
+ end
25
+ end
26
+
27
+ private
28
+ def get_theme
29
+ @theme = Theme.first || Theme.create
30
+ end
31
+
32
+ end
@@ -0,0 +1,37 @@
1
+ class Theme < ActiveRecord::Base
2
+
3
+ def locales
4
+ Dir[ File.join(RAILS_ROOT, 'themes', self.current, 'locales', '*.{rb,yml}') ]
5
+ end
6
+
7
+ def self.available_themes(theme)
8
+ themes = []
9
+ current_theme = {:name => 'default', :preview_image => '/images/no_preview.gif', :description => 'default theme'}
10
+ theme_path = File.join(RAILS_ROOT, Disguise::THEME_PATH)
11
+
12
+ Dir.glob("#{theme_path}/*").each do |theme_directory|
13
+ if File.directory?(theme_directory)
14
+ theme_name = File.basename(theme_directory)
15
+
16
+ image = Dir.glob(File.join(RAILS_ROOT, 'public', 'images', theme_name, 'preview.*')).first || File.join('/', 'images', 'no_preview.gif')
17
+ image = image.gsub(File.join(RAILS_ROOT, 'public'), '')
18
+
19
+ description = ''
20
+ description_file = File.join(theme_directory, 'description.txt')
21
+ if File.exist?(description_file)
22
+ f = File.new(description_file, "r")
23
+ description = f.read
24
+ f.close
25
+ end
26
+
27
+ theme = {:name => theme_name, :preview_image => image, :description => description}
28
+ themes << theme
29
+
30
+ current_theme = theme if theme.current == theme_name
31
+ end
32
+ end
33
+
34
+ [current_theme, themes]
35
+ end
36
+
37
+ end
@@ -0,0 +1,7 @@
1
+ <div class="theme-block">
2
+ <% form_for @theme, :url => admin_theme_path, :html => { :method => :put } do |f| -%>
3
+ <%= f.hidden_field :theme, :value => theme[:name] %>
4
+ <%= image_submit_tag theme[:preview_image] %>
5
+ <%= theme[:description] %>
6
+ <% end -%>
7
+ </div>
@@ -0,0 +1,10 @@
1
+ <h1><%= t('disguise.set_theme') %></h1>
2
+
3
+ <h2><%= t('disguise.current_theme') %></h2>
4
+ <div id="current-theme">
5
+ <%= render :partial => 'admin/themes/theme', :object => @current_theme %>
6
+ </div>
7
+
8
+ <h2><%= t('disguise.activate_theme_message') %></h2>
9
+ <%= error_messages_for :theme %>
10
+ <%= render :partial => 'admin/themes/theme', :collection => @themes %>
@@ -0,0 +1,4 @@
1
+ <div id="theme-instructions">
2
+ <p><%= t('disguise.no_themes_message') %></p>
3
+ <pre>./script/generate theme theme_name</pre>
4
+ </div>
@@ -0,0 +1,6 @@
1
+ ActionController::Routing::Routes.draw do |map|
2
+ # admin
3
+ map.namespace :admin do |a|
4
+ a.resource :theme, :controller => 'disguise/themes'
5
+ end
6
+ end
@@ -0,0 +1,11 @@
1
+ class CreateThemes < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :themes, :force => true do |t|
4
+ t.string "current"
5
+ end
6
+ end
7
+
8
+ def self.down
9
+ drop_table :themes
10
+ end
11
+ end
data/disguise.gemspec ADDED
@@ -0,0 +1,163 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{disguise}
5
+ s.version = "0.1.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Justin Ball"]
9
+ s.date = %q{2009-05-30}
10
+ s.description = %q{Add themes to your Rails application to easily change the view layer and impress everyone you know}
11
+ s.email = %q{justinball@gmail.com}
12
+ s.extra_rdoc_files = [
13
+ "LICENSE",
14
+ "README.rdoc"
15
+ ]
16
+ s.files = [
17
+ ".document",
18
+ ".gitignore",
19
+ "LICENSE",
20
+ "README.rdoc",
21
+ "Rakefile",
22
+ "VERSION",
23
+ "app/controllers/admin/disguise/themes_controller.rb",
24
+ "app/controllers/admin/disguise/themes_controller.rb",
25
+ "app/models/theme.rb",
26
+ "app/models/theme.rb",
27
+ "app/views/admin/themes/_theme.html.erb",
28
+ "app/views/admin/themes/_theme.html.erb",
29
+ "app/views/admin/themes/edit.html.erb",
30
+ "app/views/admin/themes/edit.html.erb",
31
+ "app/views/admin/themes/no_themes.html.erb",
32
+ "app/views/admin/themes/no_themes.html.erb",
33
+ "config/disguise_routes.rb",
34
+ "config/disguise_routes.rb",
35
+ "db/migrate/20090530170040_create_themes.rb",
36
+ "db/migrate/20090530170040_create_themes.rb",
37
+ "disguise.gemspec",
38
+ "generators/theme/USAGE",
39
+ "generators/theme/USAGE",
40
+ "generators/theme/templates/INSTALL",
41
+ "generators/theme/templates/INSTALL",
42
+ "generators/theme/templates/description.txt",
43
+ "generators/theme/templates/description.txt",
44
+ "generators/theme/templates/locales/en.yml",
45
+ "generators/theme/templates/preview.gif",
46
+ "generators/theme/templates/preview.gif",
47
+ "generators/theme/templates/stylesheets/styles.css",
48
+ "generators/theme/templates/stylesheets/styles.css",
49
+ "generators/theme/templates/views/_footer.html.erb",
50
+ "generators/theme/templates/views/_footer.html.erb",
51
+ "generators/theme/templates/views/_head.html.erb",
52
+ "generators/theme/templates/views/_head.html.erb",
53
+ "generators/theme/templates/views/_header.html.erb",
54
+ "generators/theme/templates/views/_header.html.erb",
55
+ "generators/theme/templates/views/application.html.erb",
56
+ "generators/theme/templates/views/application.html.erb",
57
+ "generators/theme/templates/views/home.html.erb",
58
+ "generators/theme/templates/views/home.html.erb",
59
+ "generators/theme/theme_generator.rb",
60
+ "generators/theme/theme_generator.rb",
61
+ "lib/action_controller/disguise_application.rb",
62
+ "lib/action_controller/disguise_application.rb",
63
+ "lib/disguise.rb",
64
+ "lib/disguise.rb",
65
+ "lib/disguise/initialize_routes.rb",
66
+ "lib/disguise/initialize_routes.rb",
67
+ "lib/disguise/tasks.rb",
68
+ "lib/disguise/tasks.rb",
69
+ "locales/ar.yml",
70
+ "locales/ar.yml",
71
+ "locales/bg.yml",
72
+ "locales/bg.yml",
73
+ "locales/ca.yml",
74
+ "locales/ca.yml",
75
+ "locales/cs.yml",
76
+ "locales/cs.yml",
77
+ "locales/da.yml",
78
+ "locales/da.yml",
79
+ "locales/de.yml",
80
+ "locales/de.yml",
81
+ "locales/el.yml",
82
+ "locales/el.yml",
83
+ "locales/en.yml",
84
+ "locales/en.yml",
85
+ "locales/es.yml",
86
+ "locales/es.yml",
87
+ "locales/fr.yml",
88
+ "locales/fr.yml",
89
+ "locales/it.yml",
90
+ "locales/it.yml",
91
+ "locales/iw.yml",
92
+ "locales/iw.yml",
93
+ "locales/ja.yml",
94
+ "locales/ja.yml",
95
+ "locales/ko.yml",
96
+ "locales/ko.yml",
97
+ "locales/lt.yml",
98
+ "locales/lt.yml",
99
+ "locales/lv.yml",
100
+ "locales/lv.yml",
101
+ "locales/nl.yml",
102
+ "locales/nl.yml",
103
+ "locales/no.yml",
104
+ "locales/no.yml",
105
+ "locales/pl.yml",
106
+ "locales/pl.yml",
107
+ "locales/pt.yml",
108
+ "locales/pt.yml",
109
+ "locales/ro.yml",
110
+ "locales/ro.yml",
111
+ "locales/ru.yml",
112
+ "locales/ru.yml",
113
+ "locales/sk.yml",
114
+ "locales/sk.yml",
115
+ "locales/sl.yml",
116
+ "locales/sl.yml",
117
+ "locales/sr.yml",
118
+ "locales/sr.yml",
119
+ "locales/sv.yml",
120
+ "locales/sv.yml",
121
+ "locales/tl.yml",
122
+ "locales/tl.yml",
123
+ "locales/uk.yml",
124
+ "locales/uk.yml",
125
+ "locales/vi.yml",
126
+ "locales/vi.yml",
127
+ "locales/zh-CN.yml",
128
+ "locales/zh-CN.yml",
129
+ "locales/zh-TW.yml",
130
+ "locales/zh-TW.yml",
131
+ "locales/zh.yml",
132
+ "locales/zh.yml",
133
+ "rails/init.rb",
134
+ "rails/init.rb",
135
+ "tasks/rails.rake",
136
+ "tasks/rails.rake",
137
+ "test/disguise_test.rb",
138
+ "test/disguise_test.rb",
139
+ "test/test_helper.rb",
140
+ "test/test_helper.rb"
141
+ ]
142
+ s.has_rdoc = true
143
+ s.homepage = %q{http://github.com/jbasdf/disguise}
144
+ s.rdoc_options = ["--charset=UTF-8"]
145
+ s.require_paths = ["lib"]
146
+ s.rubyforge_project = %q{disguise}
147
+ s.rubygems_version = %q{1.3.1}
148
+ s.summary = %q{Easy to use view theme system for Rails}
149
+ s.test_files = [
150
+ "test/disguise_test.rb",
151
+ "test/test_helper.rb"
152
+ ]
153
+
154
+ if s.respond_to? :specification_version then
155
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
156
+ s.specification_version = 2
157
+
158
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
159
+ else
160
+ end
161
+ else
162
+ end
163
+ end