This repository has been archived by the owner on Feb 22, 2023. It is now read-only.
forked from jystewart/theme_support
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME
executable file
·231 lines (157 loc) · 7.37 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
This theme_support version has been updated by Damien Le Berrigaud for Rails 2.0
http://www.webdrivenblog.com/
It was then forked for Rails 2.2 (and later 2.3) support by James Stewart - http://jystewart.net/process/
Some notes on the integration of Rails 2.3 support can be found at:
http://jystewart.net/process/tag/theme_support/
= Theme Support for Rails Applications
This plugin provides support for themes to the rails 2.2/2.3 application environment.
It supports theme specific images, stylesheets, javascripts, and views. The
views can be in ERb (rhtml) or liquid formats. Optionally, you can configure
the theme system to ignore any templates except liquid ones.
== Rails 3
This plugin has not been tested on Rails 3, and it won't be. It has been succeeded by
Lucas Florio's themes_for_rails gem. See http://github.com/lucasefe/themes_for_rails
for more info
== Tests
A test application with a range of cucumber-based tests is available separately at:
http://github.com/jystewart/theme_support_test_app
== Changes from the original version
* Rake tasks are now namespaced, eg: "rake themes:cache:create" instead of "rake theme_create_cache"
* Layouts now live within themes/[theme_name]/views/layouts to match up with Rails conventions
* Theme names must be Strings. The Rails 1 version of theme_support allowed anything that could be converted to a string, but this one won't
== Known Issues
Liquid template handling is not tested in 2.2 or 2.3
The various asset methods (theme_stylesheet_link_tag etc.) don't work in 2.2
== Usage
This plugin automatically makes any patches needed for theme support. You can
use the theme_generator to create the file structure needed, or create it
yourself.
It expects the following theme folder structure.
$app_root
themes/
[theme_name]
images/
stylesheets/
javascripts/
views/ <- you can override application views
layouts/ <- layout .html.erb templates
about.markdown
preview.png
When run in production mode, it will automatically cache the theme files so that
the web-server will deliver them in subsequent requests.
It bears noting that, like Typo, this will mean your apache/fcgi process will need
write permissions. This could be a possible security vulnerability.
With that in mind, it is best to pre-cache all of the theme files by using the
included rake tasks:
$ rake themes:cache:create
The theme file cache generates the following file structure:
$app_root
public/
themes/
[theme_name]/
images/
stylesheets/
javascripts/
There are other rake tasks available:
- rake themes:cache:create
- rake themes:cache:remove
- rake themes:cache:update
You specify which theme to use in your controller by using the 'theme' helper.
It's used just like the 'layout' helper. In fact, you can use them both
simultaneously. The following will render actions using the 'default' layout
in the 'blue_bird' theme (theme/blue_bird/layouts/default.html.erb):
class ApplicationController < ActionController::Base
layout 'default'
theme 'blue_bird'
...
end
You can also defer the theme lookup to a controller method:
class ApplicationController < ActionController::Base
layout 'default'
theme :get_theme
def get_theme
# If you let the user choose their own theme, you might
# add a User#theme field...
current_user.theme
end
...
end
Note: By setting the theme in the ApplicationController you can set
the theme for the whole application.
In your application views, there are theme specific helper tags
available to you. For ERb templates they are:
- theme_image_tag
- theme_image_path
- theme_javascript_include_tag
- theme_javascript_path
- theme_stylesheet_link_tag
- theme_stylesheet_path
For liquid templates there is a single helper, themeitem, that will determine
the path base on the theme file extension. Here's how you'd use it:
<link rel="StyleSheet" href="{% themeitem %} default.css {% endthemeitem %}" />
...
<img src="{% themeitem %} logo.png {% endthemeitem %}" />
The output from those two calls are:
<link rel="StyleSheet" href="/themes/[current_theme]/stylesheets/default.css" />
...
<img src="/themes/[current_theme]/images/logo.png" />
New in version 1.4 is ActionMailer support. Note, this is still experimental. However,
if you would like your themes to be able to override your ActionMailer views, you can
send the theme in your deliver_* method call. For example, assuming we have an ActionMailer
class named Mailer, and have implemented theme_support as shown above, here's how you would
allowing themes in emails:
def send_email
Mailer.deliver_my_email( 'a variable', :theme=>get_theme )
end
== Contributors
The theme_support pluging includs patches from the following:
* agkr
* D.J. Vogel
Thanks guys!
== Changelog
1.4.0 - Better support for Rails 1.1+. Updated the liquid themeitem tag.
Liquid layouts are no longer generated by default.Added a couple
of patches. One allows theme sub-directories. For example, you
can have:
[theme_dir]
stylesheets/
admin/
main.css
Added experimental support for themeing ActionMailer classes.
They work as normal, if you want to all theme's to override the
.html.erb views, send the theme in the deliver_* method. For
example:
Mailer.deliver_signup( user, :theme=>get_theme() )
In that example, `get_theme` is a method on the controller and at
the top we've used:
layout 'default'
theme :get_theme
1.3.0 - The theme_system component is no longer needed. All of the
theme support is driven by a single plugin named, oddly enough,
'theme_support'. Also improved theme route support. Instead of
overriding RouteSet#reload, RouteSet#draw is overridden, making
the theme support entirely transparent -- hopefully ;-)
1.2.2 - More Bug-fixes.
1.2.1 - Bug-fixes and documentation clean up.
1.2.0 - Updated actionview_ex with the new render_file additions from
Typo. Renamed the rake tasks so that they all start with
'theme' (theme_create_cache, theme_remove_cache,
theme_update_cache). You can update the system files by running:
$ ./script/generate theme _system_
Full support for Liquid templates, as well as an option to only
allow Liquid templates in a theme.
1.1.1 - Added rake tasks for pre-caching the themes, and removing the
cached themes.
1.1.0 - [Breaking] Abstraction of the Typo theme system. The themes are
now the same as is used in Typo. The theme engine itself is a
combination of plugins and a component. No more symlinks, thank
goodness.
1.0.2 - The current_theme is now retrieved from the controller. Where
symlinks are created on *nix systems, shortcuts are created
on Windows if Win32Utils is installed.
1.0.1 - Added 'themes' directory, theme definition file, and symlinks
to the appropriate directories on supported platforms.
1.0.0 - Initial release
---
Copyright (c) 2005 Matt McCray, based on code from Typo by Tobias Luetke
released under the MIT license