disguise 0.1.3 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +13 -1
- data/VERSION +1 -1
- data/app/controllers/admin/disguise/domain_themes_controller.rb +21 -0
- data/app/controllers/admin/disguise/themes_controller.rb +2 -0
- data/app/models/domain_theme.rb +21 -0
- data/app/models/theme.rb +2 -2
- data/app/views/admin/themes/_theme.html.erb +16 -2
- data/app/views/admin/themes/edit.html.erb +13 -8
- data/config/disguise_routes.rb +1 -0
- data/db/migrate/20090530170040_create_themes.rb +1 -1
- data/db/migrate/20090606153236_create_domain_themes.rb +13 -0
- data/disguise.gemspec +19 -3
- data/generators/theme/templates/INSTALL +1 -1
- data/generators/theme/theme_generator.rb +1 -1
- data/lib/action_controller/disguise_application.rb +7 -3
- data/locales/en.yml +6 -1
- data/test/rails_root/Rakefile +2 -0
- data/test/rails_root/app/controllers/admin/domain_themes_controller.rb +4 -0
- data/test/rails_root/config/initializers/disguise_init.rb +13 -0
- data/test/rails_root/db/migrate/20090530170040_create_themes.rb +1 -1
- data/test/rails_root/db/migrate/20090606153236_create_domain_themes.rb +13 -0
- data/test/rails_root/db/schema.rb +8 -28
- data/test/rails_root/test/factories.rb +9 -0
- data/test/rails_root/test/functional/admin/domain_themes_controller_test.rb +38 -0
- data/test/rails_root/test/functional/admin/themes_controller_test.rb +2 -2
- data/test/rails_root/test/functional/default_controller_test.rb +7 -0
- data/test/rails_root/test/test_helper.rb +1 -1
- data/test/rails_root/test/unit/domain_theme_test.rb +46 -0
- data/test/rails_root/test/unit/theme_test.rb +1 -1
- metadata +15 -2
data/README.rdoc
CHANGED
@@ -6,7 +6,7 @@ A simple theme system for your Rails application.
|
|
6
6
|
sudo gem install disguise
|
7
7
|
|
8
8
|
== Setup
|
9
|
-
Disguise comes with
|
9
|
+
Disguise comes with a couple of admin controllers to make changing your theme simple. By default they are not protected.
|
10
10
|
In order to prevent unauthorized users from changing your theme you can override the admin controller like this:
|
11
11
|
|
12
12
|
class Admin::ThemesController < Admin::Disguise::ThemesController
|
@@ -14,11 +14,18 @@ In order to prevent unauthorized users from changing your theme you can override
|
|
14
14
|
layout('admin')
|
15
15
|
end
|
16
16
|
|
17
|
+
class Admin::DomainThemesController < Admin::Disguise::DomainThemesController
|
18
|
+
before_filter :login_required
|
19
|
+
layout('admin')
|
20
|
+
end
|
21
|
+
|
22
|
+
|
17
23
|
Also be sure to add a route to the new controller in routes.rb:
|
18
24
|
|
19
25
|
# admin
|
20
26
|
map.namespace :admin do |a|
|
21
27
|
a.resource :theme
|
28
|
+
a.resources :domain_themes
|
22
29
|
end
|
23
30
|
|
24
31
|
=== Rake tasks
|
@@ -37,6 +44,11 @@ Generate a new theme for your Rails application using the built in theme generat
|
|
37
44
|
|
38
45
|
./script/generate theme theme_name
|
39
46
|
|
47
|
+
Disguise can run in two modes. The first is the default which let's an administrator set the current theme
|
48
|
+
via the built in admin interface. The second looks at the url of the incoming request and matches it to a theme.
|
49
|
+
To enable this second mode create an initializer in /config/initializers/disguise.rb and enter the following contents:
|
50
|
+
|
51
|
+
USE_DOMAIN_FOR_THEMES = true
|
40
52
|
|
41
53
|
== Tests
|
42
54
|
Tests require the gem installed before running. In addition, if you change any of the code
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class Admin::Disguise::DomainThemesController < ApplicationController
|
2
|
+
unloadable
|
3
|
+
|
4
|
+
def create
|
5
|
+
@domain_theme = DomainTheme.create(params[:domain_theme])
|
6
|
+
respond_to do |format|
|
7
|
+
flash[:notice] = t('disguise.theme_updated')
|
8
|
+
format.html { redirect_to edit_admin_theme_path }
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def update
|
13
|
+
@domain_theme = DomainTheme.find_by_name(params[:domain_theme][:name])
|
14
|
+
@domain_theme.update_attributes!(params[:domain_theme])
|
15
|
+
respond_to do |format|
|
16
|
+
flash[:notice] = t('disguise.theme_updated')
|
17
|
+
format.html { redirect_to edit_admin_theme_path }
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -5,6 +5,8 @@ class Admin::Disguise::ThemesController < ApplicationController
|
|
5
5
|
|
6
6
|
def edit
|
7
7
|
@current_theme, @themes = Theme.available_themes(@theme)
|
8
|
+
@domain_themes = {}
|
9
|
+
DomainTheme.all.each{|d| @domain_themes[d.name] = d}
|
8
10
|
if @themes.empty?
|
9
11
|
respond_to do |format|
|
10
12
|
format.html { render :template => 'admin/themes/no_themes' }
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class DomainTheme < ActiveRecord::Base
|
2
|
+
|
3
|
+
validates_presence_of :name, :uri
|
4
|
+
validates_uniqueness_of :name, :uri
|
5
|
+
|
6
|
+
class << self
|
7
|
+
def use_domain_themes?
|
8
|
+
USE_DOMAIN_FOR_THEMES
|
9
|
+
end
|
10
|
+
|
11
|
+
def get_theme(request)
|
12
|
+
domain_theme = get_domain_theme(request)
|
13
|
+
domain_theme.blank? ? nil : Theme.new(:name => domain_theme.name)
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_domain_theme(request)
|
17
|
+
self.find_by_uri(request.host)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
data/app/models/theme.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
class Theme < ActiveRecord::Base
|
2
2
|
|
3
3
|
def locales
|
4
|
-
Dir[ File.join(RAILS_ROOT, 'themes', self.
|
4
|
+
Dir[ File.join(RAILS_ROOT, 'themes', self.name, 'locales', '*.{rb,yml}') ]
|
5
5
|
end
|
6
6
|
|
7
7
|
# This method will iterate through all available themes in the theme directory
|
@@ -33,7 +33,7 @@ class Theme < ActiveRecord::Base
|
|
33
33
|
theme = {:name => theme_name, :preview_image => image, :description => description}
|
34
34
|
themes << theme
|
35
35
|
|
36
|
-
current_theme = theme if selected_theme.
|
36
|
+
current_theme = theme if selected_theme.name == theme_name
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
@@ -1,7 +1,21 @@
|
|
1
|
-
<div class="theme-block">
|
1
|
+
<div class="theme-block box">
|
2
|
+
<h3><%= theme[:name] %></h3>
|
2
3
|
<% form_for @theme, :url => admin_theme_path, :html => { :method => :put } do |f| -%>
|
3
|
-
<%= f.hidden_field :
|
4
|
+
<%= f.hidden_field :name, :value => theme[:name] %>
|
4
5
|
<%= image_submit_tag theme[:preview_image] %>
|
5
6
|
<%= theme[:description] %>
|
6
7
|
<% end -%>
|
8
|
+
<% if DomainTheme.use_domain_themes? -%>
|
9
|
+
<% domain_theme = @domain_themes[theme[:name]] || DomainTheme.new(:name => theme[:name]) %>
|
10
|
+
<% form_for [:admin, domain_theme] do |f| -%>
|
11
|
+
<%= f.hidden_field :name %>
|
12
|
+
<%= f.label t('disguise.theme_uri_label') %>
|
13
|
+
<%= f.text_field :uri %>
|
14
|
+
<% if domain_theme.new_record? -%>
|
15
|
+
<%= submit_tag t('disguise.add_uri') %>
|
16
|
+
<% else -%>
|
17
|
+
<%= submit_tag t('disguise.update_uri') %>
|
18
|
+
<% end -%>
|
19
|
+
<% end -%>
|
20
|
+
<% end -%>
|
7
21
|
</div>
|
@@ -1,15 +1,20 @@
|
|
1
1
|
<h1><%= t('disguise.set_theme') %></h1>
|
2
|
-
|
3
|
-
<h2><%= t('disguise.current_theme') %></h2>
|
4
2
|
<div id="current-theme">
|
5
|
-
<% if
|
6
|
-
<%=
|
7
|
-
TODO add code to remove all themes so that the application uses the default app layout.
|
3
|
+
<% if DomainTheme.use_domain_themes? -%>
|
4
|
+
<%= t('disguise.use_domain_themes') %>
|
8
5
|
<% else -%>
|
9
|
-
|
6
|
+
<h2><%= t('disguise.name_theme') %></h2>
|
7
|
+
<% if @current_theme -%>
|
8
|
+
<%= render :partial => 'admin/themes/theme', :object => @current_theme %>
|
9
|
+
<% form_for @theme, :url => admin_theme_path, :html => { :method => :put } do |f| -%>
|
10
|
+
<%= f.hidden_field :name, :value => '' %>
|
11
|
+
<%= submit_tag t('disguise.remove_all_themes') %>
|
12
|
+
<% end -%>
|
13
|
+
<% else -%>
|
14
|
+
<%= t('disguise.no_current_theme') %>
|
15
|
+
<% end -%>
|
10
16
|
<% end -%>
|
11
17
|
</div>
|
12
|
-
|
13
18
|
<h2><%= t('disguise.activate_theme_message') %></h2>
|
14
19
|
<%= error_messages_for :theme %>
|
15
|
-
<%= render :partial => 'admin/themes/theme', :collection => @themes %>
|
20
|
+
<%= render :partial => 'admin/themes/theme', :collection => @themes %>
|
data/config/disguise_routes.rb
CHANGED
@@ -0,0 +1,13 @@
|
|
1
|
+
class CreateDomainThemes < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :domain_themes, :force => true do |t|
|
4
|
+
t.string :uri
|
5
|
+
t.string :name
|
6
|
+
end
|
7
|
+
add_index :domain_themes, ["uri"]
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.down
|
11
|
+
drop_table :domain_themes
|
12
|
+
end
|
13
|
+
end
|
data/disguise.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{disguise}
|
5
|
-
s.version = "0.
|
5
|
+
s.version = "0.2.0"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Justin Ball"]
|
9
|
-
s.date = %q{2009-06-
|
9
|
+
s.date = %q{2009-06-06}
|
10
10
|
s.description = %q{Add themes to your Rails application to easily change the view layer and impress everyone you know}
|
11
11
|
s.email = %q{justinball@gmail.com}
|
12
12
|
s.extra_rdoc_files = [
|
@@ -20,8 +20,12 @@ Gem::Specification.new do |s|
|
|
20
20
|
"README.rdoc",
|
21
21
|
"Rakefile",
|
22
22
|
"VERSION",
|
23
|
+
"app/controllers/admin/disguise/domain_themes_controller.rb",
|
24
|
+
"app/controllers/admin/disguise/domain_themes_controller.rb",
|
23
25
|
"app/controllers/admin/disguise/themes_controller.rb",
|
24
26
|
"app/controllers/admin/disguise/themes_controller.rb",
|
27
|
+
"app/models/domain_theme.rb",
|
28
|
+
"app/models/domain_theme.rb",
|
25
29
|
"app/models/theme.rb",
|
26
30
|
"app/models/theme.rb",
|
27
31
|
"app/views/admin/themes/_theme.html.erb",
|
@@ -34,6 +38,8 @@ Gem::Specification.new do |s|
|
|
34
38
|
"config/disguise_routes.rb",
|
35
39
|
"db/migrate/20090530170040_create_themes.rb",
|
36
40
|
"db/migrate/20090530170040_create_themes.rb",
|
41
|
+
"db/migrate/20090606153236_create_domain_themes.rb",
|
42
|
+
"db/migrate/20090606153236_create_domain_themes.rb",
|
37
43
|
"disguise.gemspec",
|
38
44
|
"generators/theme/USAGE",
|
39
45
|
"generators/theme/USAGE",
|
@@ -137,6 +143,7 @@ Gem::Specification.new do |s|
|
|
137
143
|
"test/rails_root/.rake_tasks",
|
138
144
|
"test/rails_root/Capfile",
|
139
145
|
"test/rails_root/Rakefile",
|
146
|
+
"test/rails_root/app/controllers/admin/domain_themes_controller.rb",
|
140
147
|
"test/rails_root/app/controllers/admin/themes_controller.rb",
|
141
148
|
"test/rails_root/app/controllers/application_controller.rb",
|
142
149
|
"test/rails_root/app/controllers/default_controller.rb",
|
@@ -152,6 +159,7 @@ Gem::Specification.new do |s|
|
|
152
159
|
"test/rails_root/config/environments/production.rb",
|
153
160
|
"test/rails_root/config/environments/test.rb",
|
154
161
|
"test/rails_root/config/global_config.yml",
|
162
|
+
"test/rails_root/config/initializers/disguise_init.rb",
|
155
163
|
"test/rails_root/config/initializers/inflections.rb",
|
156
164
|
"test/rails_root/config/initializers/mime_types.rb",
|
157
165
|
"test/rails_root/config/initializers/requires.rb",
|
@@ -161,6 +169,7 @@ Gem::Specification.new do |s|
|
|
161
169
|
"test/rails_root/db/.keep",
|
162
170
|
"test/rails_root/db/migrate/20090530170040_create_themes.rb",
|
163
171
|
"test/rails_root/db/migrate/20090602041838_create_users.rb",
|
172
|
+
"test/rails_root/db/migrate/20090606153236_create_domain_themes.rb",
|
164
173
|
"test/rails_root/features/step_definitions/webrat_steps.rb",
|
165
174
|
"test/rails_root/features/support/env.rb",
|
166
175
|
"test/rails_root/public/.htaccess",
|
@@ -204,6 +213,7 @@ Gem::Specification.new do |s|
|
|
204
213
|
"test/rails_root/script/server",
|
205
214
|
"test/rails_root/test/factories.rb",
|
206
215
|
"test/rails_root/test/functional/.keep",
|
216
|
+
"test/rails_root/test/functional/admin/domain_themes_controller_test.rb",
|
207
217
|
"test/rails_root/test/functional/admin/themes_controller_test.rb",
|
208
218
|
"test/rails_root/test/functional/default_controller_test.rb",
|
209
219
|
"test/rails_root/test/integration/.keep",
|
@@ -211,6 +221,7 @@ Gem::Specification.new do |s|
|
|
211
221
|
"test/rails_root/test/mocks/test/.keep",
|
212
222
|
"test/rails_root/test/test_helper.rb",
|
213
223
|
"test/rails_root/test/unit/.keep",
|
224
|
+
"test/rails_root/test/unit/domain_theme_test.rb",
|
214
225
|
"test/rails_root/test/unit/theme_test.rb",
|
215
226
|
"test/rails_root/themes/blue/description.txt",
|
216
227
|
"test/rails_root/themes/blue/locales/blue.yml",
|
@@ -235,7 +246,8 @@ Gem::Specification.new do |s|
|
|
235
246
|
s.rubygems_version = %q{1.3.1}
|
236
247
|
s.summary = %q{Easy to use view theme system for Rails}
|
237
248
|
s.test_files = [
|
238
|
-
"test/rails_root/app/controllers/admin/
|
249
|
+
"test/rails_root/app/controllers/admin/domain_themes_controller.rb",
|
250
|
+
"test/rails_root/app/controllers/admin/themes_controller.rb",
|
239
251
|
"test/rails_root/app/controllers/application_controller.rb",
|
240
252
|
"test/rails_root/app/controllers/default_controller.rb",
|
241
253
|
"test/rails_root/app/models/user.rb",
|
@@ -244,6 +256,7 @@ Gem::Specification.new do |s|
|
|
244
256
|
"test/rails_root/config/environments/development.rb",
|
245
257
|
"test/rails_root/config/environments/production.rb",
|
246
258
|
"test/rails_root/config/environments/test.rb",
|
259
|
+
"test/rails_root/config/initializers/disguise_init.rb",
|
247
260
|
"test/rails_root/config/initializers/inflections.rb",
|
248
261
|
"test/rails_root/config/initializers/mime_types.rb",
|
249
262
|
"test/rails_root/config/initializers/requires.rb",
|
@@ -252,15 +265,18 @@ Gem::Specification.new do |s|
|
|
252
265
|
"test/rails_root/config/routes.rb",
|
253
266
|
"test/rails_root/db/migrate/20090530170040_create_themes.rb",
|
254
267
|
"test/rails_root/db/migrate/20090602041838_create_users.rb",
|
268
|
+
"test/rails_root/db/migrate/20090606153236_create_domain_themes.rb",
|
255
269
|
"test/rails_root/db/schema.rb",
|
256
270
|
"test/rails_root/features/step_definitions/webrat_steps.rb",
|
257
271
|
"test/rails_root/features/support/env.rb",
|
258
272
|
"test/rails_root/public/dispatch.rb",
|
259
273
|
"test/rails_root/script/create_project.rb",
|
260
274
|
"test/rails_root/test/factories.rb",
|
275
|
+
"test/rails_root/test/functional/admin/domain_themes_controller_test.rb",
|
261
276
|
"test/rails_root/test/functional/admin/themes_controller_test.rb",
|
262
277
|
"test/rails_root/test/functional/default_controller_test.rb",
|
263
278
|
"test/rails_root/test/test_helper.rb",
|
279
|
+
"test/rails_root/test/unit/domain_theme_test.rb",
|
264
280
|
"test/rails_root/test/unit/theme_test.rb"
|
265
281
|
]
|
266
282
|
|
@@ -1,5 +1,5 @@
|
|
1
1
|
To complete the theme you will need to modify the strings in the en.yml file that can be found in /themes/{theme_name}/locale/en.yml.
|
2
2
|
You can change most of the text in the site by changing that file.
|
3
3
|
We've created a directory in the images folder with your theme name. Place all theme specific images into that folder.
|
4
|
-
We also added a file called public/
|
4
|
+
We also added a file called public/{theme_name}.css where you can put theme specific css.
|
5
5
|
Add a description for your new theme to description.txt and a preview image named preview.gif. (You can also use a png or jpg).
|
@@ -25,7 +25,7 @@ class ThemeGenerator < Rails::Generator::NamedBase
|
|
25
25
|
#stylesheets
|
26
26
|
m.directory "public/stylesheets/themes"
|
27
27
|
m.directory "public/stylesheets/themes/#{file_name}"
|
28
|
-
m.file "stylesheets/styles.css", "public/stylesheets
|
28
|
+
m.file "stylesheets/styles.css", "public/stylesheets/#{file_name}.css"
|
29
29
|
|
30
30
|
# localization
|
31
31
|
m.file "locale/en.yml", "themes/#{file_name}/locales/en.yml"
|
@@ -13,14 +13,18 @@ module ActionController
|
|
13
13
|
module InstanceMethods
|
14
14
|
|
15
15
|
def current_theme
|
16
|
-
|
16
|
+
if DomainTheme.use_domain_themes?
|
17
|
+
@theme ||= DomainTheme.get_theme(request)
|
18
|
+
else
|
19
|
+
@theme ||= Theme.first
|
20
|
+
end
|
17
21
|
end
|
18
22
|
|
19
23
|
protected
|
20
24
|
|
21
25
|
def setup_theme
|
22
|
-
return if current_theme.blank? || current_theme.
|
23
|
-
theme_view_path = File.join(Disguise::THEME_FULL_BASE_PATH, current_theme.
|
26
|
+
return if current_theme.blank? || current_theme.name.blank?
|
27
|
+
theme_view_path = File.join(Disguise::THEME_FULL_BASE_PATH, current_theme.name, 'views')
|
24
28
|
if self.view_paths.first == theme_view_path
|
25
29
|
return
|
26
30
|
else
|
data/locales/en.yml
CHANGED
@@ -5,4 +5,9 @@ en:
|
|
5
5
|
set_theme: Set Theme
|
6
6
|
current_theme: Current Theme
|
7
7
|
activate_theme_message: Click on a theme to activate it
|
8
|
-
no_current_theme: 'Currently no theme has been selected for this application and so the default application view will be used.'
|
8
|
+
no_current_theme: 'Currently no theme has been selected for this application and so the default application view will be used.'
|
9
|
+
use_domain_themes: 'Themes are currently set to be changed based on the current url. In this mode the current theme will be determined by the url specified with each theme below.'
|
10
|
+
update_uri: Update Url
|
11
|
+
add_uri: Add Url
|
12
|
+
remove_all_themes: "Remove all themes and use default application templates"
|
13
|
+
theme_uri_label: Url for Theme
|
data/test/rails_root/Rakefile
CHANGED
@@ -0,0 +1,13 @@
|
|
1
|
+
USE_DOMAIN_FOR_THEMES = false
|
2
|
+
|
3
|
+
|
4
|
+
# TODO would love to get this to work. Right now to test the gem you have to install it and then run the tests
|
5
|
+
# This simulates loading the disguise gem, but without relying on vendor/gems
|
6
|
+
|
7
|
+
# path = File.join(File.dirname(__FILE__), *%w(.. .. .. ..))
|
8
|
+
# lib_path = File.join(path, "lib")
|
9
|
+
# app_path = File.join(path, "app")
|
10
|
+
#
|
11
|
+
# $LOAD_PATH.unshift(lib_path)
|
12
|
+
# $LOAD_PATH.unshift(app_path)
|
13
|
+
# load File.join(path, 'rails', 'init.rb')
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class CreateDomainThemes < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :domain_themes, :force => true do |t|
|
4
|
+
t.string :uri
|
5
|
+
t.string :name
|
6
|
+
end
|
7
|
+
add_index :domain_themes, ["uri"]
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.down
|
11
|
+
drop_table :domain_themes
|
12
|
+
end
|
13
|
+
end
|
@@ -9,38 +9,18 @@
|
|
9
9
|
#
|
10
10
|
# It's strongly recommended to check this file into your version control system.
|
11
11
|
|
12
|
-
ActiveRecord::Schema.define(:version =>
|
12
|
+
ActiveRecord::Schema.define(:version => 20090606153236) do
|
13
13
|
|
14
|
-
create_table "
|
15
|
-
t.string "
|
14
|
+
create_table "domain_themes", :force => true do |t|
|
15
|
+
t.string "uri"
|
16
|
+
t.string "name"
|
16
17
|
end
|
17
18
|
|
18
|
-
|
19
|
-
t.integer "creator_id"
|
20
|
-
t.string "name"
|
21
|
-
t.string "caption", :limit => 1000
|
22
|
-
t.text "description"
|
23
|
-
t.boolean "is_public", :default => true
|
24
|
-
t.integer "uploadable_id"
|
25
|
-
t.string "uploadable_type"
|
26
|
-
t.string "width"
|
27
|
-
t.string "height"
|
28
|
-
t.string "local_file_name"
|
29
|
-
t.string "local_content_type"
|
30
|
-
t.integer "local_file_size"
|
31
|
-
t.datetime "local_updated_at"
|
32
|
-
t.string "remote_file_name"
|
33
|
-
t.string "remote_content_type"
|
34
|
-
t.integer "remote_file_size"
|
35
|
-
t.datetime "remote_updated_at"
|
36
|
-
t.datetime "created_at"
|
37
|
-
t.datetime "updated_at"
|
38
|
-
end
|
19
|
+
add_index "domain_themes", ["uri"], :name => "index_domain_themes_on_uri"
|
39
20
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
add_index "uploads", ["uploadable_type"], :name => "index_uploads_on_uploadable_type"
|
21
|
+
create_table "themes", :force => true do |t|
|
22
|
+
t.string "name"
|
23
|
+
end
|
44
24
|
|
45
25
|
create_table "users", :force => true do |t|
|
46
26
|
t.string "name"
|
@@ -2,6 +2,15 @@ Factory.sequence :name do |n|
|
|
2
2
|
"a_name#{n}"
|
3
3
|
end
|
4
4
|
|
5
|
+
Factory.sequence :uri do |n|
|
6
|
+
"n#{n}.example.com"
|
7
|
+
end
|
8
|
+
|
5
9
|
Factory.define :user do |f|
|
6
10
|
f.name { Factory.next(:name) }
|
7
11
|
end
|
12
|
+
|
13
|
+
Factory.define :domain_theme do |f|
|
14
|
+
f.name { Factory.next(:name) }
|
15
|
+
f.uri { Factory.next(:uri) }
|
16
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../test_helper'
|
2
|
+
|
3
|
+
class Admin::DomainThemesControllerTest < ActionController::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@controller = Admin::DomainThemesController.new
|
7
|
+
@request = ActionController::TestRequest.new
|
8
|
+
@response = ActionController::TestResponse.new
|
9
|
+
end
|
10
|
+
|
11
|
+
context "create the domain theme" do
|
12
|
+
setup do
|
13
|
+
post :create, :domain_theme => { :name => 'red', :uri => @new_uri }
|
14
|
+
end
|
15
|
+
should_set_the_flash_to(I18n.t("disguise.theme_updated"))
|
16
|
+
should_redirect_to("edit theme") { edit_admin_theme_path }
|
17
|
+
should "create a new domain theme" do
|
18
|
+
assert_difference 'DomainTheme.count' do
|
19
|
+
post :create, :domain_theme => { :name => 'red_too', :uri => 'red_too_unique.example.com' }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "update the domain theme" do
|
25
|
+
setup do
|
26
|
+
@new_uri = 'red.example.com'
|
27
|
+
@domain_theme = Factory(:domain_theme, :name => 'red')
|
28
|
+
put :update, :domain_theme => { :name => 'red', :uri => @new_uri }
|
29
|
+
@domain_theme.reload
|
30
|
+
end
|
31
|
+
should "change the domain theme uri" do
|
32
|
+
assert_equal @domain_theme.uri, @new_uri
|
33
|
+
end
|
34
|
+
should_set_the_flash_to(I18n.t("disguise.theme_updated"))
|
35
|
+
should_redirect_to("edit theme") { edit_admin_theme_path }
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -31,10 +31,10 @@ class Admin::ThemesControllerTest < ActionController::TestCase
|
|
31
31
|
context "update the current theme" do
|
32
32
|
setup do
|
33
33
|
setup_theme
|
34
|
-
put :update, :theme => { :
|
34
|
+
put :update, :theme => { :name => 'red' }
|
35
35
|
end
|
36
36
|
should "change the current theme" do
|
37
|
-
assert_equal Theme.first.
|
37
|
+
assert_equal Theme.first.name, 'red'
|
38
38
|
end
|
39
39
|
should_set_the_flash_to(I18n.t("disguise.theme_updated"))
|
40
40
|
should_redirect_to("edit theme") { edit_admin_theme_path }
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class DomainThemeTest < ActiveSupport::TestCase
|
4
|
+
|
5
|
+
context "theme" do
|
6
|
+
setup do
|
7
|
+
@domain_theme = Factory(:domain_theme)
|
8
|
+
end
|
9
|
+
should_validate_presence_of :name, :uri
|
10
|
+
should_validate_uniqueness_of :name, :uri
|
11
|
+
end
|
12
|
+
|
13
|
+
context "theme by request" do
|
14
|
+
setup do
|
15
|
+
@valid_uri = 'green.example.com'
|
16
|
+
@invalid_uri = 'red.example.com'
|
17
|
+
@request = mock()
|
18
|
+
@domain_theme = Factory(:domain_theme, :name => 'green', :uri => @valid_uri)
|
19
|
+
end
|
20
|
+
|
21
|
+
context "valid url" do
|
22
|
+
setup do
|
23
|
+
@request.stubs(:host).returns(@valid_uri)
|
24
|
+
end
|
25
|
+
should "find the green theme" do
|
26
|
+
assert_equal 'green', DomainTheme.get_theme(@request).name
|
27
|
+
end
|
28
|
+
should "find the green domain theme" do
|
29
|
+
assert_equal @domain_theme, DomainTheme.get_domain_theme(@request)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "invalid url" do
|
34
|
+
setup do
|
35
|
+
@request.stubs(:host).returns(@invalid_uri)
|
36
|
+
end
|
37
|
+
should "not find the theme" do
|
38
|
+
assert_nil DomainTheme.get_theme(@request)
|
39
|
+
end
|
40
|
+
should "not find the domain theme" do
|
41
|
+
assert_not_equal @domain_theme, DomainTheme.get_domain_theme(@request)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -5,7 +5,7 @@ class ThemeTest < ActiveSupport::TestCase
|
|
5
5
|
context "theme" do
|
6
6
|
setup do
|
7
7
|
@theme = Theme.first || Theme.create
|
8
|
-
@theme.
|
8
|
+
@theme.name = 'blue'
|
9
9
|
@blue_theme_hash = {:name=>"blue", :description=>"Put information about your theme here", :preview_image=>"/images/blue/preview.gif"}
|
10
10
|
end
|
11
11
|
context "locales" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: disguise
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Ball
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-06-
|
12
|
+
date: 2009-06-06 00:00:00 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -29,13 +29,16 @@ files:
|
|
29
29
|
- README.rdoc
|
30
30
|
- Rakefile
|
31
31
|
- VERSION
|
32
|
+
- app/controllers/admin/disguise/domain_themes_controller.rb
|
32
33
|
- app/controllers/admin/disguise/themes_controller.rb
|
34
|
+
- app/models/domain_theme.rb
|
33
35
|
- app/models/theme.rb
|
34
36
|
- app/views/admin/themes/_theme.html.erb
|
35
37
|
- app/views/admin/themes/edit.html.erb
|
36
38
|
- app/views/admin/themes/no_themes.html.erb
|
37
39
|
- config/disguise_routes.rb
|
38
40
|
- db/migrate/20090530170040_create_themes.rb
|
41
|
+
- db/migrate/20090606153236_create_domain_themes.rb
|
39
42
|
- disguise.gemspec
|
40
43
|
- generators/theme/USAGE
|
41
44
|
- generators/theme/templates/INSTALL
|
@@ -90,6 +93,7 @@ files:
|
|
90
93
|
- test/rails_root/.rake_tasks
|
91
94
|
- test/rails_root/Capfile
|
92
95
|
- test/rails_root/Rakefile
|
96
|
+
- test/rails_root/app/controllers/admin/domain_themes_controller.rb
|
93
97
|
- test/rails_root/app/controllers/admin/themes_controller.rb
|
94
98
|
- test/rails_root/app/controllers/application_controller.rb
|
95
99
|
- test/rails_root/app/controllers/default_controller.rb
|
@@ -105,6 +109,7 @@ files:
|
|
105
109
|
- test/rails_root/config/environments/production.rb
|
106
110
|
- test/rails_root/config/environments/test.rb
|
107
111
|
- test/rails_root/config/global_config.yml
|
112
|
+
- test/rails_root/config/initializers/disguise_init.rb
|
108
113
|
- test/rails_root/config/initializers/inflections.rb
|
109
114
|
- test/rails_root/config/initializers/mime_types.rb
|
110
115
|
- test/rails_root/config/initializers/requires.rb
|
@@ -114,6 +119,7 @@ files:
|
|
114
119
|
- test/rails_root/db/.keep
|
115
120
|
- test/rails_root/db/migrate/20090530170040_create_themes.rb
|
116
121
|
- test/rails_root/db/migrate/20090602041838_create_users.rb
|
122
|
+
- test/rails_root/db/migrate/20090606153236_create_domain_themes.rb
|
117
123
|
- test/rails_root/features/step_definitions/webrat_steps.rb
|
118
124
|
- test/rails_root/features/support/env.rb
|
119
125
|
- test/rails_root/public/.htaccess
|
@@ -157,6 +163,7 @@ files:
|
|
157
163
|
- test/rails_root/script/server
|
158
164
|
- test/rails_root/test/factories.rb
|
159
165
|
- test/rails_root/test/functional/.keep
|
166
|
+
- test/rails_root/test/functional/admin/domain_themes_controller_test.rb
|
160
167
|
- test/rails_root/test/functional/admin/themes_controller_test.rb
|
161
168
|
- test/rails_root/test/functional/default_controller_test.rb
|
162
169
|
- test/rails_root/test/integration/.keep
|
@@ -164,6 +171,7 @@ files:
|
|
164
171
|
- test/rails_root/test/mocks/test/.keep
|
165
172
|
- test/rails_root/test/test_helper.rb
|
166
173
|
- test/rails_root/test/unit/.keep
|
174
|
+
- test/rails_root/test/unit/domain_theme_test.rb
|
167
175
|
- test/rails_root/test/unit/theme_test.rb
|
168
176
|
- test/rails_root/themes/blue/description.txt
|
169
177
|
- test/rails_root/themes/blue/locales/blue.yml
|
@@ -206,6 +214,7 @@ signing_key:
|
|
206
214
|
specification_version: 2
|
207
215
|
summary: Easy to use view theme system for Rails
|
208
216
|
test_files:
|
217
|
+
- test/rails_root/app/controllers/admin/domain_themes_controller.rb
|
209
218
|
- test/rails_root/app/controllers/admin/themes_controller.rb
|
210
219
|
- test/rails_root/app/controllers/application_controller.rb
|
211
220
|
- test/rails_root/app/controllers/default_controller.rb
|
@@ -215,6 +224,7 @@ test_files:
|
|
215
224
|
- test/rails_root/config/environments/development.rb
|
216
225
|
- test/rails_root/config/environments/production.rb
|
217
226
|
- test/rails_root/config/environments/test.rb
|
227
|
+
- test/rails_root/config/initializers/disguise_init.rb
|
218
228
|
- test/rails_root/config/initializers/inflections.rb
|
219
229
|
- test/rails_root/config/initializers/mime_types.rb
|
220
230
|
- test/rails_root/config/initializers/requires.rb
|
@@ -223,13 +233,16 @@ test_files:
|
|
223
233
|
- test/rails_root/config/routes.rb
|
224
234
|
- test/rails_root/db/migrate/20090530170040_create_themes.rb
|
225
235
|
- test/rails_root/db/migrate/20090602041838_create_users.rb
|
236
|
+
- test/rails_root/db/migrate/20090606153236_create_domain_themes.rb
|
226
237
|
- test/rails_root/db/schema.rb
|
227
238
|
- test/rails_root/features/step_definitions/webrat_steps.rb
|
228
239
|
- test/rails_root/features/support/env.rb
|
229
240
|
- test/rails_root/public/dispatch.rb
|
230
241
|
- test/rails_root/script/create_project.rb
|
231
242
|
- test/rails_root/test/factories.rb
|
243
|
+
- test/rails_root/test/functional/admin/domain_themes_controller_test.rb
|
232
244
|
- test/rails_root/test/functional/admin/themes_controller_test.rb
|
233
245
|
- test/rails_root/test/functional/default_controller_test.rb
|
234
246
|
- test/rails_root/test/test_helper.rb
|
247
|
+
- test/rails_root/test/unit/domain_theme_test.rb
|
235
248
|
- test/rails_root/test/unit/theme_test.rb
|