themes_for_rails 0.4.3 → 0.5.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/.travis.yml +2 -0
- data/Gemfile.lock +40 -35
- data/README.textile +11 -235
- data/Rakefile +1 -0
- data/doc/README.textile +363 -0
- data/{REVIEW_NOTES → doc/REVIEW_NOTES} +0 -0
- data/{RMU_REVIEW → doc/RMU_REVIEW} +0 -0
- data/{TODO.textile → doc/TODO.textile} +0 -0
- data/lib/themes_for_rails.rb +7 -6
- data/lib/themes_for_rails/{controller_methods.rb → action_controller.rb} +15 -9
- data/lib/themes_for_rails/action_mailer.rb +22 -0
- data/lib/themes_for_rails/action_view.rb +59 -0
- data/lib/themes_for_rails/assets_controller.rb +12 -13
- data/lib/themes_for_rails/common_methods.rb +28 -10
- data/lib/themes_for_rails/config.rb +44 -7
- data/lib/themes_for_rails/interpolation.rb +11 -0
- data/lib/themes_for_rails/railtie.rb +13 -2
- data/lib/themes_for_rails/routes.rb +15 -4
- data/lib/themes_for_rails/url_helpers.rb +16 -12
- data/lib/themes_for_rails/version.rb +2 -1
- data/test/lib/{controller_methods_test.rb → action_controller_test.rb} +59 -9
- data/test/lib/{mailer_methods_test.rb → action_mailer_test.rb} +2 -1
- data/test/lib/action_view_test.rb +54 -0
- data/test/lib/assets_controller_test.rb +11 -2
- data/test/lib/common_methods_test.rb +12 -6
- data/test/lib/config_test.rb +3 -2
- data/test/lib/integration_test.rb +12 -0
- data/test/lib/routes_test.rb +3 -2
- data/test/lib/themes_for_rails_test.rb +3 -2
- data/test/support/extensions.rb +1 -0
- data/test/test_helper.rb +1 -0
- data/themes_for_rails.gemspec +1 -0
- metadata +44 -28
- data/lib/themes_for_rails/mailer_methods.rb +0 -21
- data/lib/themes_for_rails/view_helpers.rb +0 -51
- data/test/lib/view_helpers_test.rb +0 -38
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/Gemfile.lock
CHANGED
@@ -1,45 +1,46 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
themes_for_rails (0.
|
4
|
+
themes_for_rails (0.5.0.pre)
|
5
5
|
rails (>= 3.0.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: http://rubygems.org/
|
9
9
|
specs:
|
10
10
|
abstract (1.0.0)
|
11
|
-
actionmailer (3.0.
|
12
|
-
actionpack (= 3.0.
|
13
|
-
mail (~> 2.2.
|
14
|
-
actionpack (3.0.
|
15
|
-
activemodel (= 3.0.
|
16
|
-
activesupport (= 3.0.
|
11
|
+
actionmailer (3.0.11)
|
12
|
+
actionpack (= 3.0.11)
|
13
|
+
mail (~> 2.2.19)
|
14
|
+
actionpack (3.0.11)
|
15
|
+
activemodel (= 3.0.11)
|
16
|
+
activesupport (= 3.0.11)
|
17
17
|
builder (~> 2.1.2)
|
18
18
|
erubis (~> 2.6.6)
|
19
|
-
i18n (~> 0.
|
19
|
+
i18n (~> 0.5.0)
|
20
20
|
rack (~> 1.2.1)
|
21
|
-
rack-mount (~> 0.6.
|
21
|
+
rack-mount (~> 0.6.14)
|
22
22
|
rack-test (~> 0.5.7)
|
23
23
|
tzinfo (~> 0.3.23)
|
24
|
-
activemodel (3.0.
|
25
|
-
activesupport (= 3.0.
|
24
|
+
activemodel (3.0.11)
|
25
|
+
activesupport (= 3.0.11)
|
26
26
|
builder (~> 2.1.2)
|
27
|
-
i18n (~> 0.
|
28
|
-
activerecord (3.0.
|
29
|
-
activemodel (= 3.0.
|
30
|
-
activesupport (= 3.0.
|
31
|
-
arel (~> 2.0.
|
27
|
+
i18n (~> 0.5.0)
|
28
|
+
activerecord (3.0.11)
|
29
|
+
activemodel (= 3.0.11)
|
30
|
+
activesupport (= 3.0.11)
|
31
|
+
arel (~> 2.0.10)
|
32
32
|
tzinfo (~> 0.3.23)
|
33
|
-
activeresource (3.0.
|
34
|
-
activemodel (= 3.0.
|
35
|
-
activesupport (= 3.0.
|
36
|
-
activesupport (3.0.
|
33
|
+
activeresource (3.0.11)
|
34
|
+
activemodel (= 3.0.11)
|
35
|
+
activesupport (= 3.0.11)
|
36
|
+
activesupport (3.0.11)
|
37
37
|
arel (2.0.10)
|
38
38
|
builder (2.1.2)
|
39
39
|
contest (0.1.2)
|
40
40
|
erubis (2.6.6)
|
41
41
|
abstract (>= 1.0.0)
|
42
42
|
i18n (0.5.0)
|
43
|
+
json (1.6.5)
|
43
44
|
mail (2.2.19)
|
44
45
|
activesupport (>= 2.3.6)
|
45
46
|
i18n (>= 0.4.0)
|
@@ -48,32 +49,35 @@ GEM
|
|
48
49
|
mime-types (1.17.2)
|
49
50
|
mocha (0.9.12)
|
50
51
|
polyglot (0.3.3)
|
51
|
-
rack (1.2.
|
52
|
-
rack-mount (0.6.
|
52
|
+
rack (1.2.5)
|
53
|
+
rack-mount (0.6.14)
|
53
54
|
rack (>= 1.0.0)
|
54
55
|
rack-test (0.5.7)
|
55
56
|
rack (>= 1.0)
|
56
|
-
rails (3.0.
|
57
|
-
actionmailer (= 3.0.
|
58
|
-
actionpack (= 3.0.
|
59
|
-
activerecord (= 3.0.
|
60
|
-
activeresource (= 3.0.
|
61
|
-
activesupport (= 3.0.
|
57
|
+
rails (3.0.11)
|
58
|
+
actionmailer (= 3.0.11)
|
59
|
+
actionpack (= 3.0.11)
|
60
|
+
activerecord (= 3.0.11)
|
61
|
+
activeresource (= 3.0.11)
|
62
|
+
activesupport (= 3.0.11)
|
62
63
|
bundler (~> 1.0)
|
63
|
-
railties (= 3.0.
|
64
|
-
railties (3.0.
|
65
|
-
actionpack (= 3.0.
|
66
|
-
activesupport (= 3.0.
|
64
|
+
railties (= 3.0.11)
|
65
|
+
railties (3.0.11)
|
66
|
+
actionpack (= 3.0.11)
|
67
|
+
activesupport (= 3.0.11)
|
67
68
|
rake (>= 0.8.7)
|
69
|
+
rdoc (~> 3.4)
|
68
70
|
thor (~> 0.14.4)
|
69
|
-
rake (0.
|
70
|
-
|
71
|
+
rake (0.9.2.2)
|
72
|
+
rdoc (3.12)
|
73
|
+
json (~> 1.4)
|
74
|
+
sqlite3 (1.3.5)
|
71
75
|
test-unit (2.2.0)
|
72
76
|
thor (0.14.6)
|
73
77
|
treetop (1.4.10)
|
74
78
|
polyglot
|
75
79
|
polyglot (>= 0.3.1)
|
76
|
-
tzinfo (0.3.
|
80
|
+
tzinfo (0.3.31)
|
77
81
|
|
78
82
|
PLATFORMS
|
79
83
|
ruby
|
@@ -81,6 +85,7 @@ PLATFORMS
|
|
81
85
|
DEPENDENCIES
|
82
86
|
contest
|
83
87
|
mocha
|
88
|
+
rails (= 3.0.11)
|
84
89
|
sqlite3
|
85
90
|
test-unit
|
86
91
|
themes_for_rails!
|
data/README.textile
CHANGED
@@ -1,258 +1,33 @@
|
|
1
1
|
h1. Theme For Rails (3 and hopefully later)
|
2
2
|
|
3
|
-
h2. Features list
|
3
|
+
h2. Features list
|
4
4
|
|
5
5
|
* Support for adding themes which includes stylesheets, javascripts, views and layouts.
|
6
|
+
* add a theme-image-url sass helper method for asset pipeline based themes
|
7
|
+
* update the generators and rake tasks to support asset pipeline based themes
|
8
|
+
* (NEW) works with the Rails Assets Pipeline without interfering, and leveraging it.
|
6
9
|
|
7
|
-
|
8
|
-
$app_root
|
9
|
-
themes/
|
10
|
-
[theme_name]
|
11
|
-
images/
|
12
|
-
stylesheets/
|
13
|
-
javascripts/
|
14
|
-
views/ <- you can override application views
|
15
|
-
layouts/ <- layout .rhtml or .liquid templates
|
16
|
-
</pre>
|
17
|
-
|
18
|
-
h2. Instructions
|
19
|
-
|
20
|
-
Add themes_for_rails to your Gemfile.
|
21
|
-
|
22
|
-
<pre>
|
23
|
-
gem 'themes_for_rails'
|
24
|
-
</pre>
|
25
|
-
|
26
|
-
Add themes_for_rails to your config/routes.rb
|
27
|
-
|
28
|
-
<pre>
|
29
|
-
MySuperDuperApp::Application.routes.draw do
|
30
|
-
# ...
|
31
|
-
themes_for_rails
|
32
|
-
# ...
|
33
|
-
end
|
34
|
-
</pre>
|
35
|
-
|
36
|
-
h3. And then?
|
37
|
-
|
38
|
-
Now you'll be able to use themes like this:
|
39
|
-
|
40
|
-
Inside method, for some explicit action:
|
41
|
-
|
42
|
-
<pre>
|
43
|
-
class MyController < ApplicationController
|
44
|
-
def show
|
45
|
-
theme "purple"
|
46
|
-
end
|
47
|
-
end
|
48
|
-
</pre>
|
49
|
-
|
50
|
-
Or at class level definition, in order to set a theme for more than one action. I think this is is prettier, and less invasive.
|
51
|
-
|
52
|
-
<pre>
|
53
|
-
class MyController < ApplicationController
|
54
|
-
theme "purple" # all actions will use this theme
|
55
|
-
def show
|
56
|
-
...
|
57
|
-
end
|
58
|
-
end
|
59
|
-
</pre>
|
60
|
-
|
61
|
-
You could also enable a theme for some actions only
|
62
|
-
|
63
|
-
<pre>
|
64
|
-
class MyController < ApplicationController
|
65
|
-
theme "purple", :only => :show
|
66
|
-
def show
|
67
|
-
# with theme
|
68
|
-
end
|
69
|
-
def edit
|
70
|
-
# no theme
|
71
|
-
end
|
72
|
-
end
|
73
|
-
</pre>
|
74
|
-
|
75
|
-
As a plus, you could do this to defer theme name resolution to a method:
|
76
|
-
|
77
|
-
<pre>
|
78
|
-
class MyController < ApplicationController
|
79
|
-
theme :theme_resolver
|
80
|
-
# ...
|
81
|
-
private
|
82
|
-
def theme_resolver
|
83
|
-
current_user.theme # or anything else that return a string.
|
84
|
-
end
|
85
|
-
end
|
86
|
-
</pre>
|
87
|
-
|
88
|
-
As a general rule, when passing a String, that becomes the theme name, but when a Symbol is sent, it gets treated as method message.
|
89
|
-
|
90
|
-
|
91
|
-
h3. Action Mailer integration:
|
92
|
-
|
93
|
-
As a plus, you can use it from Action Mailer too (thanks to rafaelss) like this:
|
94
|
-
|
95
|
-
<pre>
|
96
|
-
class MyMailer < ActionMailer::Base
|
97
|
-
|
98
|
-
def notify_someone
|
99
|
-
mail :theme => "blue" , :to => "some@one.com"
|
100
|
-
end
|
101
|
-
|
102
|
-
end
|
103
|
-
</pre>
|
104
|
-
|
105
|
-
Or set the theme by default like this (thanks to maxjgon):
|
106
|
-
|
107
|
-
<pre>
|
108
|
-
class MyMailer < ActionMailer::Base
|
109
|
-
|
110
|
-
default :theme => "blue"
|
111
|
-
|
112
|
-
def notify_someone
|
113
|
-
mail :to => "some@one.com"
|
114
|
-
end
|
115
|
-
|
116
|
-
end
|
117
|
-
</pre>
|
118
|
-
|
119
|
-
h3. Url Helpers
|
120
|
-
|
121
|
-
In your views you should be able to access your assets like this (given the theme 'default' is set):
|
122
|
-
|
123
|
-
<pre>
|
124
|
-
current_theme_image_path('logo.png') # => /themes/default/images/logo.png
|
125
|
-
current_theme_stylesheet_path('style') # => /themes/default/stylesheets/logo.css
|
126
|
-
current_theme_javascript_path('app') # => /themes/default/stylesheets/app.js
|
127
|
-
</pre>
|
128
|
-
|
129
|
-
Or a given theme:
|
130
|
-
|
131
|
-
<pre>
|
132
|
-
current_theme_image_path('logo.png', 'purple') # => /themes/purple/images/logo.png
|
133
|
-
</pre>
|
134
|
-
|
135
|
-
In your application views, there are theme specific helper tags
|
136
|
-
available to you. For ERb templates they are:
|
137
|
-
|
138
|
-
<pre>
|
139
|
-
theme_image_tag
|
140
|
-
theme_image_path
|
141
|
-
theme_javascript_include_tag
|
142
|
-
theme_javascript_path
|
143
|
-
theme_stylesheet_link_tag
|
144
|
-
theme_stylesheet_path
|
145
|
-
</pre>
|
146
|
-
|
147
|
-
h2. Generators
|
148
|
-
|
149
|
-
For now, it only creates the theme folder and add the "themes_for_rails" route in the routes.rb.
|
150
|
-
|
151
|
-
<pre>
|
152
|
-
rails generate themes_for_rails:install
|
153
|
-
</pre>
|
154
|
-
|
155
|
-
Inside the themes folder, it create a structure for my_theme.
|
156
|
-
|
157
|
-
<pre>
|
158
|
-
rails generate themes_for_rails:theme my_theme
|
159
|
-
</pre>
|
160
|
-
|
161
|
-
h2. Changing things
|
162
|
-
|
163
|
-
At least for now, you can change the ThemesForRails base dir in your app, in the corresponding environment file, or in your application.rb file. Do it like this:
|
164
|
-
|
165
|
-
<pre>
|
166
|
-
KillerApp::Application.configure do
|
167
|
-
#
|
168
|
-
|
169
|
-
config.themes_for_rails.base_dir = File.join(Rails.root, "tmp")
|
170
|
-
|
171
|
-
#...
|
172
|
-
end
|
173
|
-
</pre>
|
174
|
-
|
175
|
-
Thanks to matheusca, now you can change the name of the theme's dir.
|
176
|
-
|
177
|
-
<pre>
|
178
|
-
KillerApp::Application.configure do
|
179
|
-
#
|
180
|
-
|
181
|
-
config.themes_for_rails.themes_dir = "another_themes"
|
182
|
-
|
183
|
-
#...
|
184
|
-
end
|
185
|
-
</pre>
|
186
|
-
|
187
|
-
h2. Sass support
|
188
|
-
|
189
|
-
ThemesForRails will automatically add the themes paths to Sass, if sass is available.
|
190
|
-
|
191
|
-
For instance, everything you put inside themes/my_theme/stylesheets/sass will get compiled into themes/my_theme/stylesheets (duh, right?)
|
192
|
-
|
193
|
-
To bypass sass configuration, do this:
|
194
|
-
<pre>
|
195
|
-
KillerApp::Application.configure do
|
196
|
-
#
|
197
|
-
|
198
|
-
config.themes_for_rails.use_sass = false
|
199
|
-
|
200
|
-
#...
|
201
|
-
end
|
202
|
-
</pre>
|
203
|
-
|
204
|
-
h2. Another way to change things
|
205
|
-
|
206
|
-
If you don't like this approach and prefer something more like an initializer file, you could create one an put something like this.
|
207
|
-
|
208
|
-
<pre>
|
209
|
-
# Rails.root/config/initializers/themes_for_rails.rb (for instance)
|
210
|
-
ThemesForRails.config do |config|
|
211
|
-
#
|
212
|
-
config.themes_dir = 'another_themes'
|
213
|
-
# ...
|
214
|
-
end
|
215
|
-
</pre>
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
h2. Notes and Warnings.
|
220
|
-
|
221
|
-
If you are running an app in production mode, and you get the static files with no content, is because you don't have X-senfile enabled at your web server.
|
222
|
-
|
223
|
-
You can do two things:
|
224
|
-
|
225
|
-
comment out this line in your production.rb file:
|
226
|
-
|
227
|
-
config.action_dispatch.x_sendfile_header = "X-Sendfile"
|
228
|
-
|
229
|
-
or
|
230
|
-
|
231
|
-
configure your web server to use it. :)
|
10
|
+
h2. Compatibility
|
232
11
|
|
12
|
+
This gem works with Rails from version 3.0 to at least 3.2.1 (current at the moment of writing this readme file).
|
233
13
|
|
234
14
|
h2. Documentation
|
235
15
|
|
236
|
-
|
16
|
+
* "Rdoc":http://rubydoc.info/github/lucasefe/themes_for_rails/master/frames
|
17
|
+
* "Wiki":https://github.com/lucasefe/themes_for_rails/wiki
|
18
|
+
* "Old Readme File":https://github.com/lucasefe/themes_for_rails/blob/master/doc/README.textile
|
237
19
|
|
238
|
-
h2. Ideas
|
20
|
+
h2. Ideas / Inspiration
|
239
21
|
|
240
22
|
* Add ThemesForRails::Railtie for configuration, so we selectively set the plugin on or off. Also to be able to change several settings.
|
241
23
|
* -Add routes to allow access to the theme's static resources (js and cs), unless cached on public folder by capistrano / rake.-
|
242
24
|
* -Extend Action View path in order to make the views accessible. Same for the layouts.-
|
243
25
|
* More tests ford edge cases. Now I am only testing the happy paths.
|
244
26
|
|
245
|
-
h2. Things to remember.
|
246
|
-
|
247
|
-
* -Final version should be a gem. Initialization hooks doesn't work when using this as a plugin (vendor/plugins).-
|
248
|
-
* -Research about testing this kind of gem. I really don't have a clue.- Testing in place!
|
249
|
-
* I should probably load the theme list at start time, to be able to consult it as needed. I am gonna need that when dealing with runtime theme selection. Many themes are going to be used simultaneously, so I have to be able to switch view paths as fast as I can.
|
250
|
-
|
251
27
|
h2. Rails 2 Support
|
252
28
|
|
253
29
|
This gem only works with Rails 3 (duh). If you want the same exactly behavior, but for Rails 2.x, go "here":http://github.com/jystewart/theme_support .
|
254
30
|
|
255
|
-
|
256
31
|
h2. Running tests
|
257
32
|
|
258
33
|
<pre>
|
@@ -264,6 +39,7 @@ rake
|
|
264
39
|
h2. Authors and contributors
|
265
40
|
|
266
41
|
* lucasefe
|
42
|
+
* jedifreeman
|
267
43
|
* jbarreneche
|
268
44
|
* kule
|
269
45
|
* matheusmoreira
|
data/Rakefile
CHANGED
data/doc/README.textile
ADDED
@@ -0,0 +1,363 @@
|
|
1
|
+
h1. Theme For Rails (3 and hopefully later)
|
2
|
+
|
3
|
+
h2. Features list / Wish list
|
4
|
+
|
5
|
+
* Support for adding themes which includes stylesheets, javascripts, views and layouts.
|
6
|
+
* add a theme-image-url sass helper method for asset pipeline based themes
|
7
|
+
* update the generators and rake tasks to support asset pipeline based themes
|
8
|
+
|
9
|
+
<pre>
|
10
|
+
$app_root
|
11
|
+
themes/
|
12
|
+
[theme_name]
|
13
|
+
images/
|
14
|
+
stylesheets/
|
15
|
+
javascripts/
|
16
|
+
views/ <- you can override application views
|
17
|
+
layouts/ <- layout .rhtml or .liquid templates
|
18
|
+
</pre>
|
19
|
+
|
20
|
+
h2. Instructions
|
21
|
+
|
22
|
+
Add themes_for_rails to your Gemfile.
|
23
|
+
|
24
|
+
<pre>
|
25
|
+
gem 'themes_for_rails'
|
26
|
+
</pre>
|
27
|
+
|
28
|
+
Add themes_for_rails to your config/routes.rb
|
29
|
+
|
30
|
+
<pre>
|
31
|
+
MySuperDuperApp::Application.routes.draw do
|
32
|
+
# ...
|
33
|
+
themes_for_rails
|
34
|
+
# ...
|
35
|
+
end
|
36
|
+
</pre>
|
37
|
+
|
38
|
+
h3. Additional Instructions for using the Rails Asset Pipeline
|
39
|
+
|
40
|
+
In order to use themes_for_rails with the asset pipeline, you will need to configure a few settings and place your themes in the asset pipeline directory.
|
41
|
+
|
42
|
+
First, move your assets into the asset pipeline. For example:
|
43
|
+
|
44
|
+
<pre>
|
45
|
+
$app_root
|
46
|
+
app/
|
47
|
+
assets/
|
48
|
+
images/ <-- default asset pipeline folder
|
49
|
+
javascripts/ <-- default asset pipeline folder
|
50
|
+
stylesheets/ <-- default asset pipeline folder
|
51
|
+
themes/ <-- your themes root
|
52
|
+
[theme_name]
|
53
|
+
images/
|
54
|
+
stylesheets/
|
55
|
+
javascripts/
|
56
|
+
views/ <- you can override application views
|
57
|
+
layouts/ <- layout .rhtml or .liquid templates
|
58
|
+
</pre>
|
59
|
+
|
60
|
+
Create an initializer for themes in your {Rails.root}/config/initializers directory and set the themes_dir and assets_dir settings appropriately.
|
61
|
+
|
62
|
+
<pre>
|
63
|
+
# Rails.root/config/initializers/themes_for_rails.rb (for instance)
|
64
|
+
ThemesForRails.config do |config|
|
65
|
+
#
|
66
|
+
# If you have placed your themes like the example path above within the asset pipeline:
|
67
|
+
config.themes_dir = 'assets'
|
68
|
+
config.assets_dir = 'app/assets/themes'
|
69
|
+
# ...
|
70
|
+
end
|
71
|
+
</pre>
|
72
|
+
|
73
|
+
In your theme stylesheets directory, you can create an application.css file using the Sprockets require methods:
|
74
|
+
|
75
|
+
<pre>
|
76
|
+
/*
|
77
|
+
*= require global_stylesheet_name
|
78
|
+
*= require theme_name/stylesheets/stylesheet_name
|
79
|
+
*/
|
80
|
+
</pre>
|
81
|
+
|
82
|
+
As you can see, if you do not preface with the theme_name/stylesheets it will reference the root /app/assets/stylesheets path for global stylesheets (great for mixins and reset styles)
|
83
|
+
|
84
|
+
Currently, one unresolved issue with this setup is that you must pass the theme_name/images path into your sass image-url helper methods. For example, if you are including an image in the 'default' theme: <pre>image-url('default/images/background.png')</pre>
|
85
|
+
|
86
|
+
If you do not want to have your views inside the asset pipeline dir, you can alternatively configure your application like this:
|
87
|
+
|
88
|
+
<pre>
|
89
|
+
$app_root
|
90
|
+
app/
|
91
|
+
assets/
|
92
|
+
images/ <-- default asset pipeline folder
|
93
|
+
javascripts/ <-- default asset pipeline folder
|
94
|
+
stylesheets/ <-- default asset pipeline folder
|
95
|
+
themes/ <-- your themes root
|
96
|
+
[theme_name]
|
97
|
+
images/
|
98
|
+
stylesheets/
|
99
|
+
javascripts/
|
100
|
+
views/
|
101
|
+
themes/ <-- note themes folder lives under views in this scenario
|
102
|
+
[theme_name]
|
103
|
+
layouts/ <- layout .rhtml or .liquid templates
|
104
|
+
</pre>
|
105
|
+
|
106
|
+
and in your initializer, you will need to set the views_dir config setting like so:
|
107
|
+
|
108
|
+
<pre>
|
109
|
+
# Rails.root/config/initializers/themes_for_rails.rb (for instance)
|
110
|
+
ThemesForRails.config do |config|
|
111
|
+
#
|
112
|
+
# If you have placed your themes like the example path above within the asset pipeline:
|
113
|
+
config.themes_dir = 'assets'
|
114
|
+
config.assets_dir = 'app/assets/themes'
|
115
|
+
config.views_dir = 'app/views/themes'
|
116
|
+
# ...
|
117
|
+
end
|
118
|
+
</pre>
|
119
|
+
|
120
|
+
After that, the rest of the config for asset pipeline styles and whatnot mentioned above will work.
|
121
|
+
|
122
|
+
h3. And then?
|
123
|
+
|
124
|
+
Now you'll be able to use themes like this:
|
125
|
+
|
126
|
+
Inside method, for some explicit action:
|
127
|
+
|
128
|
+
<pre>
|
129
|
+
class MyController < ApplicationController
|
130
|
+
def show
|
131
|
+
theme "purple"
|
132
|
+
end
|
133
|
+
end
|
134
|
+
</pre>
|
135
|
+
|
136
|
+
Or at class level definition, in order to set a theme for more than one action. I think this is is prettier, and less invasive.
|
137
|
+
|
138
|
+
<pre>
|
139
|
+
class MyController < ApplicationController
|
140
|
+
theme "purple" # all actions will use this theme
|
141
|
+
def show
|
142
|
+
...
|
143
|
+
end
|
144
|
+
end
|
145
|
+
</pre>
|
146
|
+
|
147
|
+
You could also enable a theme for some actions only
|
148
|
+
|
149
|
+
<pre>
|
150
|
+
class MyController < ApplicationController
|
151
|
+
theme "purple", :only => :show
|
152
|
+
def show
|
153
|
+
# with theme
|
154
|
+
end
|
155
|
+
def edit
|
156
|
+
# no theme
|
157
|
+
end
|
158
|
+
end
|
159
|
+
</pre>
|
160
|
+
|
161
|
+
As a plus, you could do this to defer theme name resolution to a method:
|
162
|
+
|
163
|
+
<pre>
|
164
|
+
class MyController < ApplicationController
|
165
|
+
theme :theme_resolver
|
166
|
+
# ...
|
167
|
+
private
|
168
|
+
def theme_resolver
|
169
|
+
current_user.theme # or anything else that return a string.
|
170
|
+
end
|
171
|
+
end
|
172
|
+
</pre>
|
173
|
+
|
174
|
+
As a general rule, when passing a String, that becomes the theme name, but when a Symbol is sent, it gets treated as method message.
|
175
|
+
|
176
|
+
|
177
|
+
h3. Action Mailer integration:
|
178
|
+
|
179
|
+
As a plus, you can use it from Action Mailer too (thanks to rafaelss) like this:
|
180
|
+
|
181
|
+
<pre>
|
182
|
+
class MyMailer < ActionMailer::Base
|
183
|
+
|
184
|
+
def notify_someone
|
185
|
+
mail :theme => "blue" , :to => "some@one.com"
|
186
|
+
end
|
187
|
+
|
188
|
+
end
|
189
|
+
</pre>
|
190
|
+
|
191
|
+
Or set the theme by default like this (thanks to maxjgon):
|
192
|
+
|
193
|
+
<pre>
|
194
|
+
class MyMailer < ActionMailer::Base
|
195
|
+
|
196
|
+
default :theme => "blue"
|
197
|
+
|
198
|
+
def notify_someone
|
199
|
+
mail :to => "some@one.com"
|
200
|
+
end
|
201
|
+
|
202
|
+
end
|
203
|
+
</pre>
|
204
|
+
|
205
|
+
h3. Url Helpers
|
206
|
+
|
207
|
+
In your views you should be able to access your assets like this (given the theme 'default' is set):
|
208
|
+
|
209
|
+
<pre>
|
210
|
+
current_theme_image_path('logo.png') # => /themes/default/images/logo.png
|
211
|
+
current_theme_stylesheet_path('style') # => /themes/default/stylesheets/logo.css
|
212
|
+
current_theme_javascript_path('app') # => /themes/default/stylesheets/app.js
|
213
|
+
</pre>
|
214
|
+
|
215
|
+
Or a given theme:
|
216
|
+
|
217
|
+
<pre>
|
218
|
+
current_theme_image_path('logo.png', 'purple') # => /themes/purple/images/logo.png
|
219
|
+
</pre>
|
220
|
+
|
221
|
+
In your application views, there are theme specific helper tags
|
222
|
+
available to you. For ERb templates they are:
|
223
|
+
|
224
|
+
<pre>
|
225
|
+
theme_image_tag
|
226
|
+
theme_image_path
|
227
|
+
theme_javascript_include_tag
|
228
|
+
theme_javascript_path
|
229
|
+
theme_stylesheet_link_tag
|
230
|
+
theme_stylesheet_path
|
231
|
+
</pre>
|
232
|
+
|
233
|
+
h2. Generators
|
234
|
+
|
235
|
+
For now, it only creates the theme folder and add the "themes_for_rails" route in the routes.rb.
|
236
|
+
|
237
|
+
<pre>
|
238
|
+
rails generate themes_for_rails:install
|
239
|
+
</pre>
|
240
|
+
|
241
|
+
Inside the themes folder, it create a structure for my_theme.
|
242
|
+
|
243
|
+
<pre>
|
244
|
+
rails generate themes_for_rails:theme my_theme
|
245
|
+
</pre>
|
246
|
+
|
247
|
+
h2. Changing things
|
248
|
+
|
249
|
+
At least for now, you can change the ThemesForRails base dir in your app, in the corresponding environment file, or in your application.rb file. Do it like this:
|
250
|
+
|
251
|
+
<pre>
|
252
|
+
KillerApp::Application.configure do
|
253
|
+
#
|
254
|
+
|
255
|
+
config.themes_for_rails.base_dir = File.join(Rails.root, "tmp")
|
256
|
+
|
257
|
+
#...
|
258
|
+
end
|
259
|
+
</pre>
|
260
|
+
|
261
|
+
Thanks to matheusca, now you can change the name of the theme's dir.
|
262
|
+
|
263
|
+
<pre>
|
264
|
+
KillerApp::Application.configure do
|
265
|
+
#
|
266
|
+
|
267
|
+
config.themes_for_rails.themes_dir = "another_themes"
|
268
|
+
|
269
|
+
#...
|
270
|
+
end
|
271
|
+
</pre>
|
272
|
+
|
273
|
+
h2. Sass support
|
274
|
+
|
275
|
+
ThemesForRails will automatically add the themes paths to Sass, if sass is available.
|
276
|
+
|
277
|
+
For instance, everything you put inside themes/my_theme/stylesheets/sass will get compiled into themes/my_theme/stylesheets (duh, right?)
|
278
|
+
|
279
|
+
To bypass sass configuration, do this:
|
280
|
+
<pre>
|
281
|
+
KillerApp::Application.configure do
|
282
|
+
#
|
283
|
+
|
284
|
+
config.themes_for_rails.use_sass = false
|
285
|
+
|
286
|
+
#...
|
287
|
+
end
|
288
|
+
</pre>
|
289
|
+
|
290
|
+
h2. Another way to change things
|
291
|
+
|
292
|
+
If you don't like this approach and prefer something more like an initializer file, you could create one an put something like this.
|
293
|
+
|
294
|
+
<pre>
|
295
|
+
# Rails.root/config/initializers/themes_for_rails.rb (for instance)
|
296
|
+
ThemesForRails.config do |config|
|
297
|
+
#
|
298
|
+
config.themes_dir = 'another_themes'
|
299
|
+
# ...
|
300
|
+
end
|
301
|
+
</pre>
|
302
|
+
|
303
|
+
|
304
|
+
|
305
|
+
h2. Notes and Warnings.
|
306
|
+
|
307
|
+
If you are running an app in production mode, and you get the static files with no content, is because you don't have X-senfile enabled at your web server.
|
308
|
+
|
309
|
+
You can do two things:
|
310
|
+
|
311
|
+
comment out this line in your production.rb file:
|
312
|
+
|
313
|
+
config.action_dispatch.x_sendfile_header = "X-Sendfile"
|
314
|
+
|
315
|
+
or
|
316
|
+
|
317
|
+
configure your web server to use it. :)
|
318
|
+
|
319
|
+
|
320
|
+
h2. Documentation
|
321
|
+
|
322
|
+
"Read it here":http://rubydoc.info/github/lucasefe/themes_for_rails/master/frames
|
323
|
+
|
324
|
+
h2. Ideas
|
325
|
+
|
326
|
+
* Add ThemesForRails::Railtie for configuration, so we selectively set the plugin on or off. Also to be able to change several settings.
|
327
|
+
* -Add routes to allow access to the theme's static resources (js and cs), unless cached on public folder by capistrano / rake.-
|
328
|
+
* -Extend Action View path in order to make the views accessible. Same for the layouts.-
|
329
|
+
* More tests ford edge cases. Now I am only testing the happy paths.
|
330
|
+
|
331
|
+
h2. Things to remember.
|
332
|
+
|
333
|
+
* -Final version should be a gem. Initialization hooks doesn't work when using this as a plugin (vendor/plugins).-
|
334
|
+
* -Research about testing this kind of gem. I really don't have a clue.- Testing in place!
|
335
|
+
* I should probably load the theme list at start time, to be able to consult it as needed. I am gonna need that when dealing with runtime theme selection. Many themes are going to be used simultaneously, so I have to be able to switch view paths as fast as I can.
|
336
|
+
|
337
|
+
h2. Rails 2 Support
|
338
|
+
|
339
|
+
This gem only works with Rails 3 (duh). If you want the same exactly behavior, but for Rails 2.x, go "here":http://github.com/jystewart/theme_support .
|
340
|
+
|
341
|
+
|
342
|
+
h2. Running tests
|
343
|
+
|
344
|
+
<pre>
|
345
|
+
gem install bundler
|
346
|
+
bundle install
|
347
|
+
rake
|
348
|
+
</pre>
|
349
|
+
|
350
|
+
h2. Authors and contributors
|
351
|
+
|
352
|
+
* lucasefe
|
353
|
+
* jbarreneche
|
354
|
+
* kule
|
355
|
+
* matheusmoreira
|
356
|
+
* rafaelss
|
357
|
+
* maxjgon
|
358
|
+
|
359
|
+
h2. Last but not least
|
360
|
+
|
361
|
+
If you are using this gem, please, take a minute to recommend me at Working With Rails.
|
362
|
+
|
363
|
+
<a href="http://www.workingwithrails.com/recommendation/new/person/7277-lucas-florio"><img alt="Recommend Me" src="http://workingwithrails.com/images/tools/compact-small.jpg" /></a>
|