themes_for_rails4 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +8 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +2 -0
  5. data/Gemfile +3 -0
  6. data/Gemfile.lock +117 -0
  7. data/LICENSE +21 -0
  8. data/README.textile +53 -0
  9. data/Rakefile +11 -0
  10. data/doc/README.textile +380 -0
  11. data/doc/REVIEW_NOTES +0 -0
  12. data/doc/RMU_REVIEW +26 -0
  13. data/doc/TODO.textile +3 -0
  14. data/lib/generators/themes_for_rails/install_generator.rb +16 -0
  15. data/lib/generators/themes_for_rails/templates/theme/images/.gitkeep +0 -0
  16. data/lib/generators/themes_for_rails/templates/theme/javascripts/.gitkeep +0 -0
  17. data/lib/generators/themes_for_rails/templates/theme/stylesheets/.gitkeep +0 -0
  18. data/lib/generators/themes_for_rails/templates/theme/views/layouts/.gitkeep +0 -0
  19. data/lib/generators/themes_for_rails/theme_generator.rb +14 -0
  20. data/lib/tasks/themes_for_rails.rake +40 -0
  21. data/lib/themes_for_rails/action_controller.rb +32 -0
  22. data/lib/themes_for_rails/action_mailer.rb +22 -0
  23. data/lib/themes_for_rails/action_view.rb +66 -0
  24. data/lib/themes_for_rails/assets_controller.rb +68 -0
  25. data/lib/themes_for_rails/common_methods.rb +98 -0
  26. data/lib/themes_for_rails/config.rb +79 -0
  27. data/lib/themes_for_rails/digested_action_view.rb +64 -0
  28. data/lib/themes_for_rails/interpolation.rb +11 -0
  29. data/lib/themes_for_rails/railtie.rb +42 -0
  30. data/lib/themes_for_rails/routes.rb +30 -0
  31. data/lib/themes_for_rails/url_helpers.rb +27 -0
  32. data/lib/themes_for_rails/version.rb +4 -0
  33. data/lib/themes_for_rails.rb +73 -0
  34. data/test/dummy_app/.gitignore +4 -0
  35. data/test/dummy_app/Gemfile +30 -0
  36. data/test/dummy_app/Rakefile +7 -0
  37. data/test/dummy_app/another_themes/another_default/images/logo.png +0 -0
  38. data/test/dummy_app/another_themes/another_default/images/nested/logo.png +0 -0
  39. data/test/dummy_app/another_themes/another_default/javascripts/app.js +1 -0
  40. data/test/dummy_app/another_themes/another_default/stylesheets/style.css +0 -0
  41. data/test/dummy_app/another_themes/another_default/stylesheets/style2.css +3 -0
  42. data/test/dummy_app/another_themes/another_default/views/layouts/default.html.erb +10 -0
  43. data/test/dummy_app/another_themes/another_default/views/products/index.html.erb +0 -0
  44. data/test/dummy_app/app/controllers/application_controller.rb +3 -0
  45. data/test/dummy_app/app/helpers/application_helper.rb +2 -0
  46. data/test/dummy_app/app/views/layouts/application.html.erb +14 -0
  47. data/test/dummy_app/config/application.rb +42 -0
  48. data/test/dummy_app/config/boot.rb +13 -0
  49. data/test/dummy_app/config/database.yml +18 -0
  50. data/test/dummy_app/config/environment.rb +5 -0
  51. data/test/dummy_app/config/environments/development.rb +26 -0
  52. data/test/dummy_app/config/environments/production.rb +49 -0
  53. data/test/dummy_app/config/environments/test.rb +35 -0
  54. data/test/dummy_app/config/initializers/backtrace_silencers.rb +7 -0
  55. data/test/dummy_app/config/initializers/inflections.rb +10 -0
  56. data/test/dummy_app/config/initializers/mime_types.rb +5 -0
  57. data/test/dummy_app/config/initializers/secret_token.rb +7 -0
  58. data/test/dummy_app/config/initializers/session_store.rb +8 -0
  59. data/test/dummy_app/config/locales/en.yml +5 -0
  60. data/test/dummy_app/config/routes.rb +4 -0
  61. data/test/dummy_app/config.ru +4 -0
  62. data/test/dummy_app/db/seeds.rb +7 -0
  63. data/test/dummy_app/empty_themes/.gitkeep +0 -0
  64. data/test/dummy_app/lib/tasks/.gitkeep +0 -0
  65. data/test/dummy_app/public/404.html +26 -0
  66. data/test/dummy_app/public/422.html +26 -0
  67. data/test/dummy_app/public/500.html +26 -0
  68. data/test/dummy_app/public/favicon.ico +0 -0
  69. data/test/dummy_app/public/images/rails.png +0 -0
  70. data/test/dummy_app/public/index.html +239 -0
  71. data/test/dummy_app/public/javascripts/application.js +2 -0
  72. data/test/dummy_app/public/javascripts/controls.js +965 -0
  73. data/test/dummy_app/public/javascripts/dragdrop.js +974 -0
  74. data/test/dummy_app/public/javascripts/effects.js +1123 -0
  75. data/test/dummy_app/public/javascripts/prototype.js +6001 -0
  76. data/test/dummy_app/public/javascripts/rails.js +175 -0
  77. data/test/dummy_app/public/robots.txt +5 -0
  78. data/test/dummy_app/public/stylesheets/.gitkeep +0 -0
  79. data/test/dummy_app/script/rails +6 -0
  80. data/test/dummy_app/themes/default/images/logo.png +0 -0
  81. data/test/dummy_app/themes/default/images/nested/logo.png +0 -0
  82. data/test/dummy_app/themes/default/javascripts/app.js +1 -0
  83. data/test/dummy_app/themes/default/javascripts/app.min.js +0 -0
  84. data/test/dummy_app/themes/default/stylesheets/images/logo.png +0 -0
  85. data/test/dummy_app/themes/default/stylesheets/style.css +0 -0
  86. data/test/dummy_app/themes/default/stylesheets/style2.css +3 -0
  87. data/test/dummy_app/themes/default/views/layouts/default.html.erb +10 -0
  88. data/test/dummy_app/themes/default/views/products/index.html.erb +0 -0
  89. data/test/lib/action_controller_test.rb +170 -0
  90. data/test/lib/action_mailer_test.rb +35 -0
  91. data/test/lib/action_view_test.rb +54 -0
  92. data/test/lib/assets_controller_test.rb +73 -0
  93. data/test/lib/common_methods_test.rb +28 -0
  94. data/test/lib/config_test.rb +26 -0
  95. data/test/lib/integration_test.rb +12 -0
  96. data/test/lib/routes_test.rb +40 -0
  97. data/test/lib/themes_for_rails_test.rb +18 -0
  98. data/test/support/extensions.rb +19 -0
  99. data/test/test_helper.rb +12 -0
  100. data/themes_for_rails.gemspec +25 -0
  101. metadata +280 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6a72e664f53d3d34f71ff0cbb6096f8058c694fa
4
+ data.tar.gz: 6dc0f2abaec5f2f6ca2eeece355b4866b8714309
5
+ SHA512:
6
+ metadata.gz: a81364248c59bd2fdae3f83cb1fb46180a90bb264fe38747341bb70f1b114dd1ceb52b488d9760aaa6ff713136d1a6a5d85ddaf7756f1fb8e77cd6cf266a88d9
7
+ data.tar.gz: a5927642b68c108a7f5feb88da7c0bf5626648a7923c9c8f9591408fbd761a481f430f395a27b7ca9d38e33051297340b236a7469f89e51c83732377ce6b7e4a
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ .bundle
2
+ pkg
3
+ tmp
4
+ .DS_Store
5
+ spec/dummy/db/*.sqlite3
6
+ spec/dummy/log/test.log
7
+ .svn
8
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/.travis.yml ADDED
@@ -0,0 +1,2 @@
1
+ rvm:
2
+ - 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://ruby.taobao.org"
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,117 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ themes_for_rails4 (1.5.1)
5
+ rails (>= 3.0.0)
6
+
7
+ GEM
8
+ remote: https://ruby.taobao.org/
9
+ specs:
10
+ actionmailer (4.2.1)
11
+ actionpack (= 4.2.1)
12
+ actionview (= 4.2.1)
13
+ activejob (= 4.2.1)
14
+ mail (~> 2.5, >= 2.5.4)
15
+ rails-dom-testing (~> 1.0, >= 1.0.5)
16
+ actionpack (4.2.1)
17
+ actionview (= 4.2.1)
18
+ activesupport (= 4.2.1)
19
+ rack (~> 1.6)
20
+ rack-test (~> 0.6.2)
21
+ rails-dom-testing (~> 1.0, >= 1.0.5)
22
+ rails-html-sanitizer (~> 1.0, >= 1.0.1)
23
+ actionview (4.2.1)
24
+ activesupport (= 4.2.1)
25
+ builder (~> 3.1)
26
+ erubis (~> 2.7.0)
27
+ rails-dom-testing (~> 1.0, >= 1.0.5)
28
+ rails-html-sanitizer (~> 1.0, >= 1.0.1)
29
+ activejob (4.2.1)
30
+ activesupport (= 4.2.1)
31
+ globalid (>= 0.3.0)
32
+ activemodel (4.2.1)
33
+ activesupport (= 4.2.1)
34
+ builder (~> 3.1)
35
+ activerecord (4.2.1)
36
+ activemodel (= 4.2.1)
37
+ activesupport (= 4.2.1)
38
+ arel (~> 6.0)
39
+ activesupport (4.2.1)
40
+ i18n (~> 0.7)
41
+ json (~> 1.7, >= 1.7.7)
42
+ minitest (~> 5.1)
43
+ thread_safe (~> 0.3, >= 0.3.4)
44
+ tzinfo (~> 1.1)
45
+ arel (6.0.0)
46
+ builder (3.2.2)
47
+ contest (0.1.3)
48
+ erubis (2.7.0)
49
+ globalid (0.3.5)
50
+ activesupport (>= 4.1.0)
51
+ i18n (0.7.0)
52
+ json (1.8.3)
53
+ loofah (2.0.2)
54
+ nokogiri (>= 1.5.9)
55
+ mail (2.6.3)
56
+ mime-types (>= 1.16, < 3)
57
+ metaclass (0.0.1)
58
+ mime-types (2.6.1)
59
+ mini_portile (0.6.2)
60
+ minitest (5.7.0)
61
+ mocha (0.12.2)
62
+ metaclass (~> 0.0.1)
63
+ nokogiri (1.6.6.2)
64
+ mini_portile (~> 0.6.0)
65
+ rack (1.6.4)
66
+ rack-test (0.6.3)
67
+ rack (>= 1.0)
68
+ rails (4.2.1)
69
+ actionmailer (= 4.2.1)
70
+ actionpack (= 4.2.1)
71
+ actionview (= 4.2.1)
72
+ activejob (= 4.2.1)
73
+ activemodel (= 4.2.1)
74
+ activerecord (= 4.2.1)
75
+ activesupport (= 4.2.1)
76
+ bundler (>= 1.3.0, < 2.0)
77
+ railties (= 4.2.1)
78
+ sprockets-rails
79
+ rails-deprecated_sanitizer (1.0.3)
80
+ activesupport (>= 4.2.0.alpha)
81
+ rails-dom-testing (1.0.6)
82
+ activesupport (>= 4.2.0.beta, < 5.0)
83
+ nokogiri (~> 1.6.0)
84
+ rails-deprecated_sanitizer (>= 1.0.1)
85
+ rails-html-sanitizer (1.0.2)
86
+ loofah (~> 2.0)
87
+ railties (4.2.1)
88
+ actionpack (= 4.2.1)
89
+ activesupport (= 4.2.1)
90
+ rake (>= 0.8.7)
91
+ thor (>= 0.18.1, < 2.0)
92
+ rake (10.4.2)
93
+ sprockets (3.2.0)
94
+ rack (~> 1.0)
95
+ sprockets-rails (2.3.2)
96
+ actionpack (>= 3.0)
97
+ activesupport (>= 3.0)
98
+ sprockets (>= 2.8, < 4.0)
99
+ sqlite3 (1.3.6)
100
+ test-unit (2.5.1)
101
+ thor (0.19.1)
102
+ thread_safe (0.3.5)
103
+ tzinfo (1.2.2)
104
+ thread_safe (~> 0.1)
105
+
106
+ PLATFORMS
107
+ ruby
108
+
109
+ DEPENDENCIES
110
+ contest
111
+ mocha
112
+ sqlite3
113
+ test-unit
114
+ themes_for_rails4!
115
+
116
+ BUNDLED WITH
117
+ 1.10.5
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) Lucas Florio
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.textile ADDED
@@ -0,0 +1,53 @@
1
+ h1. Theme For Rails (3 and hopefully later)
2
+
3
+ h2. Features 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
+ * (NEW) works with the Rails Assets Pipeline without interfering, and leveraging it.
9
+
10
+ h2. Compatibility
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).
13
+
14
+ h2. Documentation
15
+
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
19
+
20
+ h2. Ideas / Inspiration
21
+
22
+ * Add ThemesForRails::Railtie for configuration, so we selectively set the plugin on or off. Also to be able to change several settings.
23
+ * -Add routes to allow access to the theme's static resources (js and cs), unless cached on public folder by capistrano / rake.-
24
+ * -Extend Action View path in order to make the views accessible. Same for the layouts.-
25
+ * More tests ford edge cases. Now I am only testing the happy paths.
26
+
27
+ h2. Rails 2 Support
28
+
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 .
30
+
31
+ h2. Running tests
32
+
33
+ <pre>
34
+ gem install bundler
35
+ bundle install
36
+ rake
37
+ </pre>
38
+
39
+ h2. Authors and contributors
40
+
41
+ * lucasefe
42
+ * jedifreeman
43
+ * jbarreneche
44
+ * kule
45
+ * matheusmoreira
46
+ * rafaelss
47
+ * maxjgon
48
+
49
+ h2. Last but not least
50
+
51
+ If you are using this gem, please, take a minute to recommend me at Working With Rails.
52
+
53
+ <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>
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env rake
2
+ # encoding: utf-8
3
+ require "bundler/gem_tasks"
4
+ task :default => :test
5
+
6
+ require 'rake/testtask'
7
+ Rake::TestTask.new(:test) do |test|
8
+ test.libs << 'lib' << 'test'
9
+ test.pattern = 'test/**/*_test.rb'
10
+ test.verbose = true
11
+ end
@@ -0,0 +1,380 @@
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
+ You will need to enable asset digests in your rails app. This is normally enabled in production mode but you can add it to your development environment to
43
+ test locally.
44
+
45
+ <pre>
46
+ # config/environments/development.rb
47
+
48
+ config.assets.digest = true
49
+
50
+ </pre>
51
+
52
+ h4. PLEASE ADD themes_for_rails TO THE ASSETS GROUP IN YOUR GEMFILE!
53
+ In order to automatically add the themes to your asset pipeline you need to add the themes_for_rails gem to the assets group in your Gemfile.
54
+
55
+
56
+ First, move your assets into the asset pipeline. For example:
57
+
58
+ <pre>
59
+ $app_root
60
+ app/
61
+ assets/
62
+ images/ <-- default asset pipeline folder
63
+ javascripts/ <-- default asset pipeline folder
64
+ stylesheets/ <-- default asset pipeline folder
65
+ themes/ <-- your themes root
66
+ [theme_name]
67
+ assets/ <-- this is your theme_assets_dir
68
+ [theme_name] <-- this ensures that the assets are namespaced and don't clobber eachother.
69
+ images/
70
+ stylesheets/
71
+ javascripts/
72
+ views/ <- you can override application views
73
+ layouts/ <- layout .rhtml or .liquid templates
74
+ </pre>
75
+
76
+ Create an initializer for themes in your {Rails.root}/config/initializers directory and set the themes_dir and assets_dir settings appropriately.
77
+
78
+ <pre>
79
+ # Rails.root/config/initializers/themes_for_rails.rb (for instance)
80
+ ThemesForRails.config do |config|
81
+ #
82
+ # If you have placed your themes like the example path above within the asset pipeline:
83
+ config.assets_dir = 'app/assets/themes/:name/assets'
84
+ # ...
85
+ end
86
+ </pre>
87
+
88
+ In your theme stylesheets directory, you can create an application.css file using the Sprockets require methods:
89
+
90
+ <pre>
91
+ /*
92
+ *= require global_stylesheet_name
93
+ *= require theme_name/stylesheets/stylesheet_name
94
+ */
95
+ </pre>
96
+
97
+ 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)
98
+
99
+ 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>
100
+
101
+ If you do not want to have your views inside the asset pipeline dir, you can alternatively configure your application like this:
102
+
103
+ <pre>
104
+ $app_root
105
+ app/
106
+ assets/
107
+ images/ <-- default asset pipeline folder
108
+ javascripts/ <-- default asset pipeline folder
109
+ stylesheets/ <-- default asset pipeline folder
110
+ themes/ <-- your themes root
111
+ [theme_name]
112
+ assets/ <-- this is your theme_assets_dir
113
+ [theme_name] <-- this ensures that the assets are namespaced and don't clobber eachother.
114
+ images/
115
+ stylesheets/
116
+ javascripts/
117
+ views/
118
+ themes/ <-- note themes folder lives under views in this scenario
119
+ [theme_name]
120
+ layouts/ <- layout .rhtml or .liquid templates
121
+ </pre>
122
+
123
+ and in your initializer, you will need to set the views_dir config setting like so:
124
+
125
+ <pre>
126
+ # Rails.root/config/initializers/themes_for_rails.rb (for instance)
127
+ ThemesForRails.config do |config|
128
+ #
129
+ # If you have placed your themes like the example path above within the asset pipeline:
130
+ config.themes_dir = 'assets'
131
+ config.assets_dir = 'app/assets/themes/:name/assets'
132
+ config.views_dir = 'app/views/themes'
133
+ # ...
134
+ end
135
+ </pre>
136
+
137
+ After that, the rest of the config for asset pipeline styles and whatnot mentioned above will work.
138
+
139
+ h3. And then?
140
+
141
+ Now you'll be able to use themes like this:
142
+
143
+ Inside method, for some explicit action:
144
+
145
+ <pre>
146
+ class MyController < ApplicationController
147
+ def show
148
+ theme "purple"
149
+ end
150
+ end
151
+ </pre>
152
+
153
+ 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.
154
+
155
+ <pre>
156
+ class MyController < ApplicationController
157
+ theme "purple" # all actions will use this theme
158
+ def show
159
+ ...
160
+ end
161
+ end
162
+ </pre>
163
+
164
+ You could also enable a theme for some actions only
165
+
166
+ <pre>
167
+ class MyController < ApplicationController
168
+ theme "purple", :only => :show
169
+ def show
170
+ # with theme
171
+ end
172
+ def edit
173
+ # no theme
174
+ end
175
+ end
176
+ </pre>
177
+
178
+ As a plus, you could do this to defer theme name resolution to a method:
179
+
180
+ <pre>
181
+ class MyController < ApplicationController
182
+ theme :theme_resolver
183
+ # ...
184
+ private
185
+ def theme_resolver
186
+ current_user.theme # or anything else that return a string.
187
+ end
188
+ end
189
+ </pre>
190
+
191
+ 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.
192
+
193
+
194
+ h3. Action Mailer integration:
195
+
196
+ As a plus, you can use it from Action Mailer too (thanks to rafaelss) like this:
197
+
198
+ <pre>
199
+ class MyMailer < ActionMailer::Base
200
+
201
+ def notify_someone
202
+ mail :theme => "blue" , :to => "some@one.com"
203
+ end
204
+
205
+ end
206
+ </pre>
207
+
208
+ Or set the theme by default like this (thanks to maxjgon):
209
+
210
+ <pre>
211
+ class MyMailer < ActionMailer::Base
212
+
213
+ default :theme => "blue"
214
+
215
+ def notify_someone
216
+ mail :to => "some@one.com"
217
+ end
218
+
219
+ end
220
+ </pre>
221
+
222
+ h3. Url Helpers
223
+
224
+ In your views you should be able to access your assets like this (given the theme 'default' is set):
225
+
226
+ <pre>
227
+ current_theme_image_path('logo.png') # => /assets/default/images/logo.png
228
+ current_theme_stylesheet_path('style') # => /assets/default/stylesheets/logo.css
229
+ current_theme_javascript_path('app') # => /assets/default/stylesheets/app.js
230
+ </pre>
231
+
232
+ Or a given theme:
233
+
234
+ <pre>
235
+ current_theme_image_path('logo.png', 'purple') # => /assets/purple/images/logo.png
236
+ </pre>
237
+
238
+ In your application views, there are theme specific helper tags
239
+ available to you. For ERb templates they are:
240
+
241
+ <pre>
242
+ theme_image_tag
243
+ theme_image_path
244
+ theme_javascript_include_tag
245
+ theme_javascript_path
246
+ theme_stylesheet_link_tag
247
+ theme_stylesheet_path
248
+ </pre>
249
+
250
+ h2. Generators
251
+
252
+ For now, it only creates the theme folder and add the "themes_for_rails" route in the routes.rb.
253
+
254
+ <pre>
255
+ rails generate themes_for_rails:install
256
+ </pre>
257
+
258
+ Inside the themes folder, it create a structure for my_theme.
259
+
260
+ <pre>
261
+ rails generate themes_for_rails:theme my_theme
262
+ </pre>
263
+
264
+ h2. Changing things
265
+
266
+ 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:
267
+
268
+ <pre>
269
+ KillerApp::Application.configure do
270
+ #
271
+
272
+ config.themes_for_rails.base_dir = File.join(Rails.root, "tmp")
273
+
274
+ #...
275
+ end
276
+ </pre>
277
+
278
+ Thanks to matheusca, now you can change the name of the theme's dir.
279
+
280
+ <pre>
281
+ KillerApp::Application.configure do
282
+ #
283
+
284
+ config.themes_for_rails.themes_dir = "another_themes"
285
+
286
+ #...
287
+ end
288
+ </pre>
289
+
290
+ h2. Sass support
291
+
292
+ ThemesForRails will automatically add the themes paths to Sass, if sass is available.
293
+
294
+ For instance, everything you put inside themes/my_theme/stylesheets/sass will get compiled into themes/my_theme/stylesheets (duh, right?)
295
+
296
+ To bypass sass configuration, do this:
297
+ <pre>
298
+ KillerApp::Application.configure do
299
+ #
300
+
301
+ config.themes_for_rails.use_sass = false
302
+
303
+ #...
304
+ end
305
+ </pre>
306
+
307
+ h2. Another way to change things
308
+
309
+ If you don't like this approach and prefer something more like an initializer file, you could create one an put something like this.
310
+
311
+ <pre>
312
+ # Rails.root/config/initializers/themes_for_rails.rb (for instance)
313
+ ThemesForRails.config do |config|
314
+ #
315
+ config.themes_dir = 'another_themes'
316
+ # ...
317
+ end
318
+ </pre>
319
+
320
+
321
+
322
+ h2. Notes and Warnings.
323
+
324
+ 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.
325
+
326
+ You can do two things:
327
+
328
+ comment out this line in your production.rb file:
329
+
330
+ config.action_dispatch.x_sendfile_header = "X-Sendfile"
331
+
332
+ or
333
+
334
+ configure your web server to use it. :)
335
+
336
+
337
+ h2. Documentation
338
+
339
+ "Read it here":http://rubydoc.info/github/lucasefe/themes_for_rails/master/frames
340
+
341
+ h2. Ideas
342
+
343
+ * Add ThemesForRails::Railtie for configuration, so we selectively set the plugin on or off. Also to be able to change several settings.
344
+ * -Add routes to allow access to the theme's static resources (js and cs), unless cached on public folder by capistrano / rake.-
345
+ * -Extend Action View path in order to make the views accessible. Same for the layouts.-
346
+ * More tests ford edge cases. Now I am only testing the happy paths.
347
+
348
+ h2. Things to remember.
349
+
350
+ * -Final version should be a gem. Initialization hooks doesn't work when using this as a plugin (vendor/plugins).-
351
+ * -Research about testing this kind of gem. I really don't have a clue.- Testing in place!
352
+ * 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.
353
+
354
+ h2. Rails 2 Support
355
+
356
+ 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 .
357
+
358
+
359
+ h2. Running tests
360
+
361
+ <pre>
362
+ gem install bundler
363
+ bundle install
364
+ rake
365
+ </pre>
366
+
367
+ h2. Authors and contributors
368
+
369
+ * lucasefe
370
+ * jbarreneche
371
+ * kule
372
+ * matheusmoreira
373
+ * rafaelss
374
+ * maxjgon
375
+
376
+ h2. Last but not least
377
+
378
+ If you are using this gem, please, take a minute to recommend me at Working With Rails.
379
+
380
+ <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>
data/doc/REVIEW_NOTES ADDED
File without changes
data/doc/RMU_REVIEW ADDED
@@ -0,0 +1,26 @@
1
+ - Setup
2
+
3
+ Add themes_for_rails to your Gemfile.
4
+
5
+ gem 'themes_for_rails'
6
+
7
+ Add themes_for_rails to your config/routes.rb
8
+
9
+ Then follow the instructions provided in the README file.
10
+
11
+ - Accomplishments
12
+
13
+ I've accomplished several things:
14
+
15
+ * I got the chance to know a lot about the Raisl 3 public API. I have worked a lot on hooking the themes support cleanly, and not using monkey patching.
16
+
17
+ * I also learned about testing with the minimal. In this project I am not using rspec, but test_unit, so this was different from what I was used to.
18
+
19
+ * This time, I build the library step by step, one part at a time, which was pretty different from what I did with the twitter lib. Progressively built. I required to do design first and then coding. Leasson learned.
20
+
21
+ * Finally, coding style. Use vertical spaces.
22
+
23
+ ---NOTE---
24
+
25
+ More information reading the specs, or the README.
26
+
data/doc/TODO.textile ADDED
@@ -0,0 +1,3 @@
1
+ - Allow to change the way the view path is added. Before or after.
2
+
3
+ - Research how to integrate SASS to this scheme.
@@ -0,0 +1,16 @@
1
+ module ThemesForRails
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ desc "Creates a ThemeForRails basic structure."
5
+
6
+ def create_themes_folder
7
+ empty_directory(ThemesForRails.config.themes_path)
8
+ end
9
+
10
+ def add_themes_for_rails_routes
11
+ route "themes_for_rails"
12
+ end
13
+
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,14 @@
1
+ module ThemesForRails
2
+ module Generators
3
+ class ThemeGenerator < Rails::Generators::NamedBase
4
+ source_root File.expand_path("../templates", __FILE__)
5
+ desc "Creates an empty theme."
6
+
7
+ def create_theme
8
+ theme_dir = File.join(ThemesForRails.config.themes_path, name)
9
+ directory 'theme', theme_dir
10
+ end
11
+
12
+ end
13
+ end
14
+ end