themes_on_rails 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +110 -0
- data/Rakefile +60 -0
- data/lib/generators/themes_on_rails/templates/all.css +9 -0
- data/lib/generators/themes_on_rails/templates/all.js +7 -0
- data/lib/generators/themes_on_rails/templates/layout.html.erb +14 -0
- data/lib/generators/themes_on_rails/templates/layout.html.haml +9 -0
- data/lib/generators/themes_on_rails/theme_generator.rb +52 -0
- data/lib/themes_on_rails/action_controller.rb +61 -0
- data/lib/themes_on_rails/controller_additions.rb +13 -0
- data/lib/themes_on_rails/engine.rb +6 -0
- data/lib/themes_on_rails/railtie.rb +17 -0
- data/lib/themes_on_rails/version.rb +3 -0
- data/lib/themes_on_rails.rb +9 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/javascripts/posts.js +2 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/assets/stylesheets/posts.css +4 -0
- data/spec/dummy/app/assets/stylesheets/scaffold.css +56 -0
- data/spec/dummy/app/controllers/application_controller.rb +9 -0
- data/spec/dummy/app/controllers/posts_controller.rb +68 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/helpers/posts_helper.rb +2 -0
- data/spec/dummy/app/models/post.rb +2 -0
- data/spec/dummy/app/themes/basic_blue/assets/javascripts/basic_blue/all.js +7 -0
- data/spec/dummy/app/themes/basic_blue/assets/stylesheets/basic_blue/all.css +9 -0
- data/spec/dummy/app/themes/basic_blue/views/layouts/basic_blue.html.haml +9 -0
- data/spec/dummy/app/themes/basic_blue/views/posts/_form.html.erb +25 -0
- data/spec/dummy/app/themes/basic_blue/views/posts/edit.html.erb +6 -0
- data/spec/dummy/app/themes/basic_blue/views/posts/index.html.erb +29 -0
- data/spec/dummy/app/themes/basic_blue/views/posts/new.html.erb +5 -0
- data/spec/dummy/app/themes/basic_blue/views/posts/show.html.erb +15 -0
- data/spec/dummy/app/themes/professional_blue/assets/javascripts/professional_blue/all.js +7 -0
- data/spec/dummy/app/themes/professional_blue/assets/stylesheets/professional_blue/all.css +9 -0
- data/spec/dummy/app/themes/professional_blue/views/layouts/professional_blue.html.haml +9 -0
- data/spec/dummy/app/themes/professional_blue/views/posts/_form.html.erb +25 -0
- data/spec/dummy/app/themes/professional_blue/views/posts/edit.html.erb +6 -0
- data/spec/dummy/app/themes/professional_blue/views/posts/index.html.erb +29 -0
- data/spec/dummy/app/themes/professional_blue/views/posts/new.html.erb +5 -0
- data/spec/dummy/app/themes/professional_blue/views/posts/show.html.erb +15 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/app/views/posts/_form.html.erb +25 -0
- data/spec/dummy/app/views/posts/edit.html.erb +6 -0
- data/spec/dummy/app/views/posts/index.html.erb +29 -0
- data/spec/dummy/app/views/posts/new.html.erb +5 -0
- data/spec/dummy/app/views/posts/show.html.erb +14 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config/application.rb +22 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +29 -0
- data/spec/dummy/config/environments/production.rb +80 -0
- data/spec/dummy/config/environments/test.rb +36 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +12 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +58 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/20131120082307_create_posts.rb +10 -0
- data/spec/dummy/db/schema.rb +23 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +1581 -0
- data/spec/dummy/log/test.log +4042 -0
- data/spec/dummy/public/404.html +58 -0
- data/spec/dummy/public/422.html +58 -0
- data/spec/dummy/public/500.html +57 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/spec/controllers/posts_controller_spec.rb +47 -0
- data/spec/dummy/spec/spec_helper.rb +44 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/0cfcea8e64323f692964ade04baf71bf +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/1b2584b22e1970da0ea00056c0149492 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/1e8f75a6b5b33970fb8e397347caa0a1 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/24204f742af588c8166d3160b500d20f +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/301390a2f715e632e51eaceadc864bd8 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/3059f09ecb35a9d6a17cc629cf142cad +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/371bf96e99717688ed7313a0c53f4212 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/3773504c128301fa4ae43322c265863c +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/416150dc3ac35079c94273cc46e90aa6 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/510da110ae528e2d22533be39ff696c5 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/5384ad85f52d3272dbc64d46ef3876a4 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/6fc757c2c8329244ca95d6909865bbc2 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/8b1b55ee928fcc1ca79651b5a54d12b1 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/97b428fb2be48bdef1c2edc6895007e6 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/a144f874a0fbcfbf57e914e54950b2b8 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/a6505a19f1ef24ad643489939529b237 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/aea240771414d6f51f0eeffa97de34c0 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/c6062fc388a3fcd36f0407b7de58b073 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/c85016e7bbd4f3adbb7635d01f85d39b +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/d066c004d1fd26ae76a61303a7a18145 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/spec/dummy/tmp/cache/assets/development/sprockets/fbce05c1fbdc18388ed134c8e4100ac8 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/0cfcea8e64323f692964ade04baf71bf +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/1b2584b22e1970da0ea00056c0149492 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/301390a2f715e632e51eaceadc864bd8 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/3059f09ecb35a9d6a17cc629cf142cad +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/371bf96e99717688ed7313a0c53f4212 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/3773504c128301fa4ae43322c265863c +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/416150dc3ac35079c94273cc46e90aa6 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/5384ad85f52d3272dbc64d46ef3876a4 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/6fc757c2c8329244ca95d6909865bbc2 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/8b1b55ee928fcc1ca79651b5a54d12b1 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/97b428fb2be48bdef1c2edc6895007e6 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/a144f874a0fbcfbf57e914e54950b2b8 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/a6505a19f1ef24ad643489939529b237 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/aea240771414d6f51f0eeffa97de34c0 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/c6062fc388a3fcd36f0407b7de58b073 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/c85016e7bbd4f3adbb7635d01f85d39b +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/d066c004d1fd26ae76a61303a7a18145 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/spec/dummy/tmp/cache/assets/test/sprockets/fbce05c1fbdc18388ed134c8e4100ac8 +0 -0
- data/spec/generators/themes_on_rails/theme_generator_spec.rb +67 -0
- data/spec/lib/action_controller_spec.rb +45 -0
- data/spec/lib/assets_path_spec.rb +15 -0
- data/spec/lib/controller_additions_spec.rb +22 -0
- data/spec/spec_helper.rb +22 -0
- metadata +330 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d025d6301cdac27ace8312ce556aaac0e017be31
|
4
|
+
data.tar.gz: a71f476abd9d2660d7c42f9a29482db576166599
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8e7bbbd53e44d4eca576d9fbc0cc3f2bbbec9aae7ab6931cc0e69ee5f265bb09c8a8dd496ba5c496cef2772b11a9953457e043b8b7ce01a52289d6efdd23678b
|
7
|
+
data.tar.gz: c889fd6896ec5c11be83a59d3a4299eb697266e72d1932cb33be144d8dde06398dcbf4bcb9f3c459fe77ef40392130771abee3343e527ba29bf78691653b61d7
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2013 Chamnap Chhorn
|
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.md
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
# ThemesOnRails [![Build Status](https://travis-ci.org/yoolk/themes_on_rails.png?branch=master)](https://travis-ci.org/yoolk/themes_on_rails) [![Dependency Status](https://gemnasium.com/yoolk/themes_on_rails.png)](https://gemnasium.com/yoolk/themes_on_rails) [![Code Climate](https://codeclimate.com/github/yoolk/themes_on_rails.png)](https://codeclimate.com/github/yoolk/themes_on_rails) [![Coverage Status](https://coveralls.io/repos/yoolk/themes_on_rails/badge.png?branch=master)](https://coveralls.io/r/yoolk/themes_on_rails?branch=master)
|
2
|
+
|
3
|
+
## Installation
|
4
|
+
|
5
|
+
The simplest way to install is to use Bundler.
|
6
|
+
|
7
|
+
Add this gem to your Gemfile:
|
8
|
+
|
9
|
+
gem "themes_on_rails"
|
10
|
+
|
11
|
+
Then, use Bundler to install the gem and its dependencies:
|
12
|
+
|
13
|
+
$ bundle install
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
A theme is composed of two things:
|
18
|
+
|
19
|
+
1. Views: templates and layouts (erb, haml, or other template engines)
|
20
|
+
2. Assets: images, javascripts, stylesheets
|
21
|
+
|
22
|
+
### Generator
|
23
|
+
|
24
|
+
To generate theme inside your app:
|
25
|
+
|
26
|
+
$ rails g themes_on_rails:theme theme_name
|
27
|
+
|
28
|
+
<pre>
|
29
|
+
app/
|
30
|
+
themes/
|
31
|
+
[theme_name]/
|
32
|
+
assets/
|
33
|
+
images/
|
34
|
+
[theme_name]/
|
35
|
+
stylesheets/
|
36
|
+
[theme_name]/
|
37
|
+
all.css
|
38
|
+
javascripts/
|
39
|
+
[theme_name]/
|
40
|
+
all.js
|
41
|
+
views/
|
42
|
+
layouts/
|
43
|
+
[theme_name].html.erb
|
44
|
+
</pre>
|
45
|
+
|
46
|
+
It's best advisable to namespace your assets directory so that it won't conflict with assets in other themes.
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
image_tag "professional_blue/logo.png" # => app/themes/professional_blue/assets/images/professional_blue/logo.png
|
50
|
+
javascript_link_tag "professional_blue/all" # => app/themes/professional_blue/assets/javascripts/professional_blue/all.js
|
51
|
+
stylesheet_link_tag "professional_blue/all" # => app/themes/professional_blue/assets/stylesheets/professional_blue/all.css
|
52
|
+
```
|
53
|
+
|
54
|
+
### Controller
|
55
|
+
|
56
|
+
You can set theme in your controllers by using the `theme` declaration. For example:
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
class HomeController < ApplicationController
|
60
|
+
theme "basic"
|
61
|
+
|
62
|
+
def index
|
63
|
+
...
|
64
|
+
end
|
65
|
+
end
|
66
|
+
```
|
67
|
+
|
68
|
+
With this declaration, all of the views rendered by the home controller will use `app/themes/basic/views/home/index.html.erb` as its templates and use `app/themes/basic/views/layouts/basic.html.erb`.
|
69
|
+
|
70
|
+
You can use a symbol to defer the choice of theme until a request is processed:
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
class HomeController < ApplicationController
|
74
|
+
theme :theme_resolver
|
75
|
+
|
76
|
+
def index
|
77
|
+
...
|
78
|
+
end
|
79
|
+
|
80
|
+
private
|
81
|
+
|
82
|
+
def theme_resolver
|
83
|
+
params[:theme].presence || "professional"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
```
|
87
|
+
|
88
|
+
Now, if there is a `params[:theme]`, it will use that theme. Otherwise, it will use **professional** theme.
|
89
|
+
|
90
|
+
You can even use an inline method, such as a **Proc**, to determine the theme. For example, if you pass a **Proc** object, the block you give the **Proc** will be given the controller instance, so the theme can be determined based on the current request:
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
class HomeController < ApplicationController
|
94
|
+
theme Proc.new { |controller| params[:theme].presence || "professional" }
|
95
|
+
end
|
96
|
+
```
|
97
|
+
|
98
|
+
Theme specified at the controller level support the `:only` and `:except` options. These options take either a method name, or an array of method names, corresponding to method names within the controller:
|
99
|
+
|
100
|
+
```ruby
|
101
|
+
class HomeController < ApplicationController
|
102
|
+
theme "basic", except: [:rss]
|
103
|
+
end
|
104
|
+
```
|
105
|
+
|
106
|
+
With this declaration, the **basic** theme would be used for everything but the `rss` index methods.
|
107
|
+
|
108
|
+
## Authors
|
109
|
+
|
110
|
+
* [Chamnap Chhorn](https://github.com/chamnap)
|
data/Rakefile
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
|
8
|
+
# bunlder tasks
|
9
|
+
Bundler::GemHelper.install_tasks
|
10
|
+
|
11
|
+
# dummy app tasks
|
12
|
+
require 'rake'
|
13
|
+
load File.expand_path('spec/dummy/Rakefile')
|
14
|
+
|
15
|
+
ENV["RAILS_ENV"] = "test"
|
16
|
+
|
17
|
+
# spec tasks
|
18
|
+
require 'rspec/core'
|
19
|
+
require 'rspec/core/rake_task'
|
20
|
+
|
21
|
+
# Add two methods to Rake::Task
|
22
|
+
class Rake::Task
|
23
|
+
def overwrite(&block)
|
24
|
+
@actions.clear
|
25
|
+
prerequisites.clear
|
26
|
+
enhance(&block)
|
27
|
+
end
|
28
|
+
|
29
|
+
def abandon
|
30
|
+
prerequisites.clear
|
31
|
+
@actions.clear
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# Remove orginial `rake spec`
|
36
|
+
Rake::Task[:spec].abandon
|
37
|
+
|
38
|
+
RSpec::Core::RakeTask.new(:spec => 'db:test:prepare') do |spec|
|
39
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
40
|
+
end
|
41
|
+
|
42
|
+
task :default => "spec:all"
|
43
|
+
|
44
|
+
namespace :spec do
|
45
|
+
%w(rails_40 rails_32).each do |gemfile|
|
46
|
+
desc "Run Tests against #{gemfile}"
|
47
|
+
task gemfile do
|
48
|
+
sh "BUNDLE_GEMFILE='gemfiles/#{gemfile}.gemfile' bundle --quiet"
|
49
|
+
sh "BUNDLE_GEMFILE='gemfiles/#{gemfile}.gemfile' bundle exec rake spec"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
desc "Run Tests against rails versions"
|
54
|
+
task :all do
|
55
|
+
%w(rails_40 rails_32).each do |gemfile|
|
56
|
+
sh "BUNDLE_GEMFILE='gemfiles/#{gemfile}.gemfile' bundle --quiet"
|
57
|
+
sh "BUNDLE_GEMFILE='gemfiles/#{gemfile}.gemfile' bundle exec rake spec"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll automatically include all the stylesheets available in this directory
|
3
|
+
* and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
|
4
|
+
* the top of the compiled file, but it's generally better to create a new file per style scope.
|
5
|
+
*
|
6
|
+
|
7
|
+
*= require_self
|
8
|
+
*= require_tree .
|
9
|
+
*/
|
@@ -0,0 +1,7 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into including all the files listed below.
|
2
|
+
// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
|
3
|
+
// be included in the compiled file accessible from http://example.com/assets/application.js
|
4
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
5
|
+
// the compiled file.
|
6
|
+
//
|
7
|
+
//= require_tree .
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title><%= theme_name.humanize %></title>
|
5
|
+
<%%= stylesheet_link_tag "<%= %Q{#{theme_name}/all} %>", media: "all", "data-turbolinks-track" => true %>
|
6
|
+
<%%= javascript_include_tag "<%= %Q{#{theme_name}/all} %>", "data-turbolinks-track" => true %>
|
7
|
+
<%%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<%%= yield %>
|
12
|
+
|
13
|
+
</body>
|
14
|
+
</html>
|
@@ -0,0 +1,9 @@
|
|
1
|
+
!!!
|
2
|
+
%html
|
3
|
+
%head
|
4
|
+
%title <%= "#{theme_name.humanize}" %>
|
5
|
+
= stylesheet_link_tag "<%= %Q{#{theme_name}/all} %>", media: "all", "data-turbolinks-track" => true
|
6
|
+
= javascript_include_tag "<%= %Q{#{theme_name}/all} %>", "data-turbolinks-track" => true
|
7
|
+
= csrf_meta_tags
|
8
|
+
%body
|
9
|
+
= yield
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module ThemesOnRails
|
2
|
+
module Generators
|
3
|
+
class ThemeGenerator < Rails::Generators::Base
|
4
|
+
source_root File.expand_path("../templates", __FILE__)
|
5
|
+
argument :theme_name, type: :string
|
6
|
+
desc "Creates a new theme"
|
7
|
+
|
8
|
+
def create_theme_directory
|
9
|
+
empty_directory theme_views_layout
|
10
|
+
empty_directory theme_images_directory
|
11
|
+
empty_directory theme_javascripts_directory
|
12
|
+
empty_directory theme_stylesheets_directory
|
13
|
+
create_file "#{theme_images_directory}/.gitkeep", nil
|
14
|
+
end
|
15
|
+
|
16
|
+
def copy_manifest_files
|
17
|
+
copy_file "all.js", "#{theme_javascripts_directory}/all.js"
|
18
|
+
copy_file "all.css", "#{theme_stylesheets_directory}/all.css"
|
19
|
+
end
|
20
|
+
|
21
|
+
def copy_layout_file
|
22
|
+
if Rails.configuration.app_generators.rails[:template_engine] == :haml
|
23
|
+
template "layout.html.haml", "#{theme_views_layout}/#{theme_name}.html.haml"
|
24
|
+
else
|
25
|
+
template "layout.html.erb", "#{theme_views_layout}/#{theme_name}.html.erb"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def theme_directory
|
32
|
+
"app/themes/#{theme_name}"
|
33
|
+
end
|
34
|
+
|
35
|
+
def theme_views_layout
|
36
|
+
"#{theme_directory}/views/layouts"
|
37
|
+
end
|
38
|
+
|
39
|
+
def theme_images_directory
|
40
|
+
"#{theme_directory}/assets/images/#{theme_name}"
|
41
|
+
end
|
42
|
+
|
43
|
+
def theme_javascripts_directory
|
44
|
+
"#{theme_directory}/assets/javascripts/#{theme_name}"
|
45
|
+
end
|
46
|
+
|
47
|
+
def theme_stylesheets_directory
|
48
|
+
"#{theme_directory}/assets/stylesheets/#{theme_name}"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module ThemesOnRails
|
2
|
+
class ActionController
|
3
|
+
attr_reader :theme_name
|
4
|
+
|
5
|
+
class << self
|
6
|
+
def apply_theme(controller_class, theme, options={})
|
7
|
+
filter_method = before_filter_method(options)
|
8
|
+
options = options.slice(:only, :except)
|
9
|
+
|
10
|
+
controller_class.send(filter_method, options) do |controller|
|
11
|
+
|
12
|
+
# initialize
|
13
|
+
instance = ThemesOnRails::ActionController.new(controller, theme)
|
14
|
+
|
15
|
+
# set layout
|
16
|
+
controller_class.layout(instance.theme_name, options)
|
17
|
+
|
18
|
+
# prepend view path
|
19
|
+
controller.prepend_view_path instance.theme_view_path
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def before_filter_method(options)
|
26
|
+
case Rails::VERSION::MAJOR
|
27
|
+
when 3
|
28
|
+
options.delete(:prepend) ? :prepend_before_filter : :before_filter
|
29
|
+
when 4
|
30
|
+
options.delete(:prepend) ? :prepend_before_action : :before_action
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def initialize(controller, theme)
|
36
|
+
@controller = controller
|
37
|
+
@theme_name = _theme_name(theme)
|
38
|
+
end
|
39
|
+
|
40
|
+
def theme_view_path
|
41
|
+
"#{prefix_path}/#{@theme_name}/views"
|
42
|
+
end
|
43
|
+
|
44
|
+
def prefix_path
|
45
|
+
"#{Rails.root}/app/themes"
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def _theme_name(theme)
|
51
|
+
case theme
|
52
|
+
when String then theme
|
53
|
+
when Proc then theme.call(@controller).to_s
|
54
|
+
when Symbol then @controller.respond_to?(theme, true) ? @controller.send(theme).to_s : theme.to_s
|
55
|
+
else
|
56
|
+
raise ArgumentError,
|
57
|
+
"String, Proc, or Symbol, expected for `theme'; you passed #{theme.inspect}"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module ThemesOnRails
|
2
|
+
module ControllerAdditions
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
module ClassMethods
|
6
|
+
def theme(theme, options={})
|
7
|
+
@_theme = theme
|
8
|
+
@_theme_options = options
|
9
|
+
ThemesOnRails::ActionController.apply_theme(self, theme, options)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module ThemesOnRails
|
2
|
+
class Railtie < ::Rails::Railtie
|
3
|
+
|
4
|
+
initializer "themes_on_rails.action_controller" do |app|
|
5
|
+
ActiveSupport.on_load :action_controller do
|
6
|
+
include ThemesOnRails::ControllerAdditions
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
initializer "themes_on_rails.assets_path" do |app|
|
11
|
+
Dir.glob("#{Rails.root}/app/themes/*/assets/*").each do |dir|
|
12
|
+
app.config.assets.paths << dir
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require "themes_on_rails/version"
|
2
|
+
require "active_support/concern"
|
3
|
+
|
4
|
+
module ThemesOnRails
|
5
|
+
autoload :ActionController, "themes_on_rails/action_controller"
|
6
|
+
autoload :ControllerAdditions, "themes_on_rails/controller_additions"
|
7
|
+
end
|
8
|
+
|
9
|
+
require "themes_on_rails/railtie" if defined?(Rails)
|
@@ -0,0 +1,28 @@
|
|
1
|
+
== README
|
2
|
+
|
3
|
+
This README would normally document whatever steps are necessary to get the
|
4
|
+
application up and running.
|
5
|
+
|
6
|
+
Things you may want to cover:
|
7
|
+
|
8
|
+
* Ruby version
|
9
|
+
|
10
|
+
* System dependencies
|
11
|
+
|
12
|
+
* Configuration
|
13
|
+
|
14
|
+
* Database creation
|
15
|
+
|
16
|
+
* Database initialization
|
17
|
+
|
18
|
+
* How to run the test suite
|
19
|
+
|
20
|
+
* Services (job queues, cache servers, search engines, etc.)
|
21
|
+
|
22
|
+
* Deployment instructions
|
23
|
+
|
24
|
+
* ...
|
25
|
+
|
26
|
+
|
27
|
+
Please feel free to use a different markup language if you do not plan to run
|
28
|
+
<tt>rake doc:app</tt>.
|