├── .coveralls.yml ├── .gitignore ├── .rspec ├── .ruby-gemset ├── .ruby-version ├── .travis.yml ├── CHANGELOG.md ├── Gemfile ├── Guardfile ├── MIT-LICENSE ├── README.md ├── Rakefile ├── gemfiles ├── rails_32.gemfile ├── rails_40.gemfile ├── rails_41.gemfile └── rails_42.gemfile ├── lib ├── generators │ └── themes_on_rails │ │ ├── templates │ │ ├── all.css │ │ ├── all.js │ │ ├── layout.html.erb │ │ ├── layout.html.haml │ │ └── layout.html.liquid │ │ └── theme_generator.rb ├── themes_on_rails.rb └── themes_on_rails │ ├── action_controller.rb │ ├── controller_additions.rb │ ├── engine.rb │ └── version.rb ├── spec ├── dummy │ ├── .rspec │ ├── README.rdoc │ ├── Rakefile │ ├── app │ │ ├── assets │ │ │ ├── images │ │ │ │ └── .keep │ │ │ ├── javascripts │ │ │ │ ├── application.js │ │ │ │ └── posts.js │ │ │ └── stylesheets │ │ │ │ ├── application.css │ │ │ │ ├── posts.css │ │ │ │ └── scaffold.css │ │ ├── controllers │ │ │ ├── application_controller.rb │ │ │ ├── concerns │ │ │ │ └── .keep │ │ │ └── posts_controller.rb │ │ ├── helpers │ │ │ ├── application_helper.rb │ │ │ └── posts_helper.rb │ │ ├── mailers │ │ │ └── .keep │ │ ├── models │ │ │ ├── .keep │ │ │ ├── concerns │ │ │ │ └── .keep │ │ │ └── post.rb │ │ ├── themes │ │ │ ├── theme_a │ │ │ │ ├── assets │ │ │ │ │ ├── images │ │ │ │ │ │ └── theme_a │ │ │ │ │ │ │ └── .gitkeep │ │ │ │ │ ├── javascripts │ │ │ │ │ │ └── theme_a │ │ │ │ │ │ │ └── all.js │ │ │ │ │ └── stylesheets │ │ │ │ │ │ └── theme_a │ │ │ │ │ │ └── all.css │ │ │ │ └── views │ │ │ │ │ ├── layouts │ │ │ │ │ └── theme_a.html.haml │ │ │ │ │ └── posts │ │ │ │ │ ├── _form.html.erb │ │ │ │ │ ├── edit.html.erb │ │ │ │ │ ├── index.html.erb │ │ │ │ │ ├── new.html.erb │ │ │ │ │ └── show.html.erb │ │ │ ├── theme_b │ │ │ │ ├── assets │ │ │ │ │ ├── images │ │ │ │ │ │ └── theme_b │ │ │ │ │ │ │ └── .gitkeep │ │ │ │ │ ├── javascripts │ │ │ │ │ │ └── theme_b │ │ │ │ │ │ │ └── all.js │ │ │ │ │ └── stylesheets │ │ │ │ │ │ └── theme_b │ │ │ │ │ │ └── all.css │ │ │ │ └── views │ │ │ │ │ ├── layouts │ │ │ │ │ ├── alternate_theme_b.html.haml │ │ │ │ │ └── theme_b.html.haml │ │ │ │ │ └── posts │ │ │ │ │ ├── _form.html.erb │ │ │ │ │ ├── edit.html.erb │ │ │ │ │ ├── index.html.erb │ │ │ │ │ ├── new.html.erb │ │ │ │ │ └── show.html.erb │ │ │ └── theme_c │ │ │ │ ├── assets │ │ │ │ ├── images │ │ │ │ │ └── theme_c │ │ │ │ │ │ ├── .gitkeep │ │ │ │ │ │ └── 1.jpg │ │ │ │ ├── javascripts │ │ │ │ │ └── theme_c │ │ │ │ │ │ └── all.js │ │ │ │ └── stylesheets │ │ │ │ │ └── theme_c │ │ │ │ │ └── all.css │ │ │ │ ├── locales │ │ │ │ ├── en.yml │ │ │ │ └── km.yml │ │ │ │ └── views │ │ │ │ ├── layouts │ │ │ │ └── theme_c.liquid │ │ │ │ └── posts │ │ │ │ ├── _partial.liquid │ │ │ │ └── index.liquid │ │ └── views │ │ │ ├── layouts │ │ │ └── application.html.erb │ │ │ └── posts │ │ │ ├── _form.html.erb │ │ │ ├── edit.html.erb │ │ │ ├── index.html.erb │ │ │ ├── new.html.erb │ │ │ └── show.html.erb │ ├── bin │ │ ├── bundle │ │ ├── rails │ │ └── rake │ ├── config.ru │ ├── config │ │ ├── application.rb │ │ ├── boot.rb │ │ ├── database.yml │ │ ├── environment.rb │ │ ├── environments │ │ │ ├── development.rb │ │ │ ├── production.rb │ │ │ └── test.rb │ │ ├── initializers │ │ │ ├── backtrace_silencers.rb │ │ │ ├── filter_parameter_logging.rb │ │ │ ├── inflections.rb │ │ │ ├── mime_types.rb │ │ │ ├── secret_token.rb │ │ │ ├── session_store.rb │ │ │ └── wrap_parameters.rb │ │ ├── locales │ │ │ └── en.yml │ │ └── routes.rb │ ├── db │ │ ├── migrate │ │ │ └── 20131120082307_create_posts.rb │ │ └── schema.rb │ ├── lib │ │ └── assets │ │ │ └── .keep │ ├── log │ │ └── .keep │ ├── public │ │ ├── 404.html │ │ ├── 422.html │ │ ├── 500.html │ │ └── favicon.ico │ └── spec │ │ ├── controllers │ │ └── posts_controller_spec.rb │ │ └── spec_helper.rb ├── generators │ └── themes_on_rails │ │ └── theme_generator_spec.rb ├── lib │ ├── action_controller_spec.rb │ ├── controller_additions_spec.rb │ └── engine_spec.rb └── spec_helper.rb └── themes_on_rails.gemspec /.coveralls.yml: -------------------------------------------------------------------------------- 1 | service_name: travis-ci 2 | repo_token: J6JIa4VxzPyO5cNl0LRtiBRjfDHXdavjU 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .bundle/ 2 | log/*.log 3 | pkg/ 4 | Gemfile.lock 5 | gemfiles/*.lock 6 | coverage/ 7 | spec/dummy/db/*.sqlite3 8 | spec/dummy/log/*.log 9 | spec/dummy/tmp/ 10 | spec/dummy/.sass-cache 11 | -------------------------------------------------------------------------------- /.rspec: -------------------------------------------------------------------------------- 1 | --color 2 | -------------------------------------------------------------------------------- /.ruby-gemset: -------------------------------------------------------------------------------- 1 | themes_on_rails -------------------------------------------------------------------------------- /.ruby-version: -------------------------------------------------------------------------------- 1 | 2.3.0 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: ruby 2 | before_install: gem install bundler -v='1.11.2' 3 | script: 4 | - bundle exec rake db:migrate --trace 5 | - bundle exec rake db:test:prepare 6 | - bundle exec rake spec 7 | rvm: 8 | - 2.0.0 9 | - 2.1.5 10 | - 2.2.1 11 | gemfile: 12 | - gemfiles/rails_32.gemfile 13 | - gemfiles/rails_40.gemfile 14 | - gemfiles/rails_41.gemfile 15 | - gemfiles/rails_42.gemfile 16 | env: 17 | - RAILS_ENV=test 18 | notifications: 19 | email: false 20 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Overview 2 | 3 | ## 0.4.0 4 | 5 | * Support Rails 5 by (victorperez)[https://github.com/victorperez] 6 | 7 | ## 0.3.1 8 | 9 | * Make it thread-safe by [lowjoel](https://github.com/lowjoel) 10 | 11 | ## 0.3.0 12 | 13 | * Support liquid templates. 14 | * Support locales in theme directory. 15 | * Support Rails 4.2.x. 16 | * Fix bug switching theme in development, #7. 17 | 18 | ## 0.2.2 19 | 20 | * Fix precompile initializer in Rails 4.1.x. 21 | 22 | ## 0.2.1 23 | 24 | * Take environment check away in precompile initializer. 25 | 26 | ## 0.2.0 27 | 28 | * Support Rails 4.1.x. 29 | * Add precompile initializer for themes located at `app/themes`. 30 | 31 | ## 0.1.0 32 | 33 | * First Release 34 | * Support Rails 3/4. 35 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gem 'rails', '~> 4.2.5' 4 | gem 'liquid-rails', '~> 0.1.3' 5 | gem 'rake', '~> 10.4.2' 6 | gem 'thin', '~> 1.6.3' 7 | gem 'jquery-rails', '~> 4.0.3' 8 | gem 'sqlite3', '~> 1.3.10' 9 | gem 'quiet_assets' 10 | gem 'pry', '~> 0.10.1' 11 | gem 'haml-rails', '~> 0.9.0' 12 | gem 'rspec-rails', '~> 3.4.0' 13 | gem 'guard-rspec', '~> 4.6.4' 14 | gem 'coveralls', require: false 15 | 16 | gemspec 17 | -------------------------------------------------------------------------------- /Guardfile: -------------------------------------------------------------------------------- 1 | # A sample Guardfile 2 | # More info at https://github.com/guard/guard#readme 3 | 4 | # Note: The cmd option is now required due to the increasing number of ways 5 | # rspec may be run, below are examples of the most common uses. 6 | # * bundler: 'bundle exec rspec' 7 | # * bundler binstubs: 'bin/rspec' 8 | # * spring: 'bin/rsspec' (This will use spring if running and you have 9 | # installed the spring binstubs per the docs) 10 | # * zeus: 'zeus rspec' (requires the server to be started separetly) 11 | # * 'just' rspec: 'rspec' 12 | guard :rspec, cmd: 'bundle exec rspec' do 13 | watch(%r{^spec/.+_spec\.rb$}) 14 | watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" } 15 | watch('spec/spec_helper.rb') { "spec" } 16 | 17 | # Rails example 18 | watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" } 19 | watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" } 20 | watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] } 21 | watch(%r{^spec/support/(.+)\.rb$}) { "spec" } 22 | watch('config/routes.rb') { "spec/routing" } 23 | watch('app/controllers/application_controller.rb') { "spec/controllers" } 24 | watch('spec/rails_helper.rb') { "spec" } 25 | 26 | # Capybara features specs 27 | watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" } 28 | 29 | # Turnip features and steps 30 | watch(%r{^spec/acceptance/(.+)\.feature$}) 31 | watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' } 32 | end 33 | 34 | -------------------------------------------------------------------------------- /MIT-LICENSE: -------------------------------------------------------------------------------- 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. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 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) [![Gem Version](https://badge.fury.io/rb/themes_on_rails.png)](http://badge.fury.io/rb/themes_on_rails) 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 | If you want to use `themes_on_rails` with `liquid` template, add one more gem to your Gemfile: 12 | 13 | gem 'liquid-rails' 14 | 15 | Then, use Bundler to install the gem and its dependencies: 16 | 17 | $ bundle install 18 | 19 | ## Usage 20 | 21 | A theme is composed of three things: 22 | 23 | 1. Assets: images, javascripts, stylesheets 24 | 2. Views: templates and layouts (erb, haml, or other template engines) 25 | 3. Locales: locales files if any 26 | 27 | ### Generator 28 | 29 | To generate theme inside your app: 30 | 31 | $ rails g themes_on_rails:theme theme_name 32 | 33 |
 34 | app/
 35 |   themes/
 36 |     [theme_name]/
 37 |       assets/
 38 |         images/
 39 |           [theme_name]/
 40 |         stylesheets/
 41 |           [theme_name]/
 42 |             all.css
 43 |         javascripts/
 44 |           [theme_name]/
 45 |             all.js
 46 |       views/
 47 |         layouts/
 48 |           [theme_name].html.erb
 49 |       locales/
 50 | 
51 | 52 | After you invoke the above command, make sure you restart your rails process. 53 | 54 | It's best advisable to namespace your assets directory so that it won't conflict with assets in other themes. 55 | 56 | ```ruby 57 | image_tag 'theme_a/logo.png' # => app/themes/theme_a/assets/images/theme_a/logo.png 58 | javascript_include_tag 'theme_a/all' # => app/themes/theme_a/assets/javascripts/theme_a/all.js 59 | stylesheet_link_tag 'theme_a/all' # => app/themes/theme_a/assets/stylesheets/theme_a/all.css 60 | ``` 61 | 62 | There is an example app at https://github.com/chamnap/themes_on_rails_example. 63 | 64 | ### Controller 65 | 66 | You can set theme in your controllers by using the `theme` declaration. For example: 67 | 68 | ```ruby 69 | class HomeController < ApplicationController 70 | theme 'basic' 71 | 72 | def index 73 | ... 74 | end 75 | end 76 | ``` 77 | 78 | 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`. 79 | 80 | You can use a symbol to defer the choice of theme until a request is processed: 81 | 82 | ```ruby 83 | class HomeController < ApplicationController 84 | theme :theme_resolver 85 | 86 | def index 87 | ... 88 | end 89 | 90 | private 91 | 92 | def theme_resolver 93 | params[:theme].presence || 'professional' 94 | end 95 | end 96 | ``` 97 | 98 | Now, if there is a `params[:theme]`, it will use that theme. Otherwise, it will use **professional** theme. 99 | 100 | 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: 101 | 102 | ```ruby 103 | class HomeController < ApplicationController 104 | theme Proc.new { |controller| controller.params[:theme].presence || 'professional' } 105 | end 106 | ``` 107 | 108 | 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: 109 | 110 | ```ruby 111 | class HomeController < ApplicationController 112 | theme 'basic', except: [:rss] 113 | end 114 | ``` 115 | 116 | With this declaration, the **basic** theme would be used for everything but the `rss` index methods. 117 | 118 | ## Authors 119 | 120 | * [Chamnap Chhorn](https://github.com/chamnap) 121 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 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_42 rails_41 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_42 rails_41 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 -------------------------------------------------------------------------------- /gemfiles/rails_32.gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gem 'rails', '~> 3.2.22' 4 | gem 'liquid-rails', '~> 0.1.0' 5 | gem 'rake', '~> 10.4.2' 6 | gem 'thin', '~> 1.6.3' 7 | gem 'jquery-rails', '~> 3.1.2' 8 | gem 'sqlite3', '~> 1.3.10' 9 | gem 'quiet_assets' 10 | gem 'pry', '~> 0.10.1' 11 | gem 'haml-rails', '~> 0.4' 12 | gem 'rspec-rails', '~> 3.2.0' 13 | gem 'guard-rspec', '~> 4.5.0' 14 | gem 'coveralls', require: false 15 | gem 'test-unit', '~> 3.0' 16 | 17 | gemspec :path => '../' 18 | -------------------------------------------------------------------------------- /gemfiles/rails_40.gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gem 'rails', '~> 4.0.13' 4 | gem 'liquid-rails', '~> 0.1.0' 5 | gem 'rake', '~> 10.4.2' 6 | gem 'thin', '~> 1.6.3' 7 | gem 'jquery-rails', '~> 3.1.2' 8 | gem 'sqlite3', '~> 1.3.10' 9 | gem 'quiet_assets' 10 | gem 'pry', '~> 0.10.1' 11 | gem 'haml-rails', '~> 0.8.2' 12 | gem 'rspec-rails', '~> 3.2.0' 13 | gem 'guard-rspec', '~> 4.5.0' 14 | gem 'coveralls', require: false 15 | 16 | gemspec :path => '../' 17 | -------------------------------------------------------------------------------- /gemfiles/rails_41.gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gem 'rails', '~> 4.1.14' 4 | gem 'liquid-rails', '~> 0.1.0' 5 | gem 'rake', '~> 10.4.2' 6 | gem 'thin', '~> 1.6.3' 7 | gem 'jquery-rails', '~> 3.1.2' 8 | gem 'sqlite3', '~> 1.3.10' 9 | gem 'quiet_assets' 10 | gem 'pry', '~> 0.10.1' 11 | gem 'haml-rails', '~> 0.8.2' 12 | gem 'rspec-rails', '~> 3.2.0' 13 | gem 'guard-rspec', '~> 4.5.0' 14 | gem 'coveralls', require: false 15 | 16 | gemspec :path => '../' 17 | -------------------------------------------------------------------------------- /gemfiles/rails_42.gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gem 'rails', '~> 4.2.5' 4 | gem 'liquid-rails', '~> 0.1.3' 5 | gem 'rake', '~> 10.4.2' 6 | gem 'thin', '~> 1.6.3' 7 | gem 'jquery-rails', '~> 4.0.3' 8 | gem 'sqlite3', '~> 1.3.10' 9 | gem 'quiet_assets' 10 | gem 'pry', '~> 0.10.1' 11 | gem 'haml-rails', '~> 0.9.0' 12 | gem 'rspec-rails', '~> 3.4.0' 13 | gem 'guard-rspec', '~> 4.6.4' 14 | gem 'coveralls', require: false 15 | 16 | gemspec :path => '../' 17 | -------------------------------------------------------------------------------- /lib/generators/themes_on_rails/templates/all.css: -------------------------------------------------------------------------------- 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 | */ -------------------------------------------------------------------------------- /lib/generators/themes_on_rails/templates/all.js: -------------------------------------------------------------------------------- 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 . -------------------------------------------------------------------------------- /lib/generators/themes_on_rails/templates/layout.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | <%= 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 | 9 | 10 | 11 | <%%= yield %> 12 | 13 | 14 | -------------------------------------------------------------------------------- /lib/generators/themes_on_rails/templates/layout.html.haml: -------------------------------------------------------------------------------- 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 -------------------------------------------------------------------------------- /lib/generators/themes_on_rails/templates/layout.html.liquid: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | <%= theme_name.humanize %> 5 | {{ '<%= "#{theme_name}/all" %>' | asset_path | javascript_include_tag }} 6 | {{ '<%= "#{theme_name}/all" %>' | asset_path | stylesheet_link_tag }} 7 | {% csrf_meta_tags %} 8 | 9 | 10 | 11 | {{ content_for_layout }} 12 | 13 | 14 | -------------------------------------------------------------------------------- /lib/generators/themes_on_rails/theme_generator.rb: -------------------------------------------------------------------------------- 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 | empty_directory theme_locales_directory 14 | create_file "#{theme_images_directory}/.gitkeep", nil 15 | create_file "#{theme_locales_directory}/.gitkeep", nil 16 | end 17 | 18 | def copy_manifest_files 19 | copy_file "all.js", "#{theme_javascripts_directory}/all.js" 20 | copy_file "all.css", "#{theme_stylesheets_directory}/all.css" 21 | end 22 | 23 | def copy_layout_file 24 | template_engine = Rails.configuration.app_generators.rails[:template_engine] 25 | if template_engine == :liquid 26 | template "layout.html.liquid", "#{theme_views_layout}/#{theme_name}.liquid" 27 | elsif template_engine == :haml 28 | template "layout.html.haml", "#{theme_views_layout}/#{theme_name}.html.haml" 29 | else 30 | template "layout.html.erb", "#{theme_views_layout}/#{theme_name}.html.erb" 31 | end 32 | end 33 | 34 | private 35 | 36 | def theme_directory 37 | "app/themes/#{theme_name}" 38 | end 39 | 40 | def theme_views_layout 41 | "#{theme_directory}/views/layouts" 42 | end 43 | 44 | def theme_images_directory 45 | "#{theme_directory}/assets/images/#{theme_name}" 46 | end 47 | 48 | def theme_javascripts_directory 49 | "#{theme_directory}/assets/javascripts/#{theme_name}" 50 | end 51 | 52 | def theme_stylesheets_directory 53 | "#{theme_directory}/assets/stylesheets/#{theme_name}" 54 | end 55 | 56 | def theme_locales_directory 57 | "#{theme_directory}/locales" 58 | end 59 | end 60 | end 61 | end 62 | -------------------------------------------------------------------------------- /lib/themes_on_rails.rb: -------------------------------------------------------------------------------- 1 | require 'themes_on_rails/version' 2 | require 'themes_on_rails/engine' 3 | require 'active_support/concern' 4 | 5 | module ThemesOnRails 6 | autoload :ActionController, 'themes_on_rails/action_controller' 7 | autoload :ControllerAdditions, 'themes_on_rails/controller_additions' 8 | 9 | def self.all 10 | Dir.glob("app/themes/*").select { |fn| !fn.start_with?('.') && File.directory?(fn) }.map { |fn| fn.split('/').last } 11 | end 12 | end -------------------------------------------------------------------------------- /lib/themes_on_rails/action_controller.rb: -------------------------------------------------------------------------------- 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 | # set layout 11 | controller_class.class_eval do 12 | define_method :layout_from_theme do 13 | theme_instance.theme_name 14 | end 15 | 16 | define_method :theme_instance do 17 | @theme_instance ||= ThemesOnRails::ActionController.new(self, theme) 18 | end 19 | 20 | define_method :current_theme do 21 | theme_instance.theme_name 22 | end 23 | 24 | private :layout_from_theme, :theme_instance 25 | layout :layout_from_theme, options 26 | helper_method :current_theme 27 | end 28 | 29 | controller_class.send(filter_method, options) do |controller| 30 | 31 | # prepend view path 32 | controller.prepend_view_path theme_instance.theme_view_path 33 | 34 | # liquid file system 35 | Liquid::Template.file_system = Liquid::Rails::FileSystem.new(theme_instance.theme_view_path) if defined?(Liquid::Rails) 36 | end 37 | end 38 | 39 | private 40 | 41 | def before_filter_method(options) 42 | case Rails::VERSION::MAJOR 43 | when 3 44 | options.delete(:prepend) ? :prepend_before_filter : :before_filter 45 | when 4, 5 46 | options.delete(:prepend) ? :prepend_before_action : :before_action 47 | end 48 | end 49 | end 50 | 51 | def initialize(controller, theme) 52 | @controller = controller 53 | @theme_name = _theme_name(theme) 54 | end 55 | 56 | def theme_view_path 57 | "#{prefix_path}/#{@theme_name}/views" 58 | end 59 | 60 | def prefix_path 61 | "#{Rails.root}/app/themes" 62 | end 63 | 64 | private 65 | 66 | def _theme_name(theme) 67 | case theme 68 | when String then theme 69 | when Proc then theme.call(@controller).to_s 70 | when Symbol then @controller.respond_to?(theme, true) ? @controller.send(theme).to_s : theme.to_s 71 | else 72 | raise ArgumentError, 73 | "String, Proc, or Symbol, expected for `theme'; you passed #{theme.inspect}" 74 | end 75 | end 76 | end 77 | end 78 | -------------------------------------------------------------------------------- /lib/themes_on_rails/controller_additions.rb: -------------------------------------------------------------------------------- 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 -------------------------------------------------------------------------------- /lib/themes_on_rails/engine.rb: -------------------------------------------------------------------------------- 1 | require 'rails/generators' 2 | 3 | module ThemesOnRails 4 | class Engine < ::Rails::Engine 5 | initializer 'themes_on_rails.action_controller' do |app| 6 | ActiveSupport.on_load :action_controller do 7 | include ThemesOnRails::ControllerAdditions 8 | end 9 | end 10 | 11 | initializer 'themes_on_rails.load_locales' do |app| 12 | app.config.i18n.load_path += Dir[Rails.root.join('app/themes/*', 'locales', '**', '*.yml').to_s] 13 | end 14 | 15 | initializer 'themes_on_rails.assets_path' do |app| 16 | Dir.glob("#{Rails.root}/app/themes/*/assets/*").each do |dir| 17 | app.config.assets.paths << dir 18 | end 19 | end 20 | 21 | initializer 'themes_on_rails.precompile' do |app| 22 | app.config.assets.precompile << Proc.new do |path, fn| 23 | if fn =~ /app\/themes/ 24 | basename = path.split('/').last 25 | if !%w(.js .css).include?(File.extname(path)) 26 | true 27 | elsif path =~ /^[^\/]+\/all((_|-).+)?\.(js|css)$/ 28 | # 1. don't allow nested: theme_a/responsive/all.js 29 | # 2. allow start_with all_ or all- 30 | # 3. allow all.js and all.css 31 | true 32 | else 33 | false 34 | end 35 | end 36 | end 37 | end 38 | end 39 | end 40 | -------------------------------------------------------------------------------- /lib/themes_on_rails/version.rb: -------------------------------------------------------------------------------- 1 | module ThemesOnRails 2 | VERSION = '0.4.0' 3 | end -------------------------------------------------------------------------------- /spec/dummy/.rspec: -------------------------------------------------------------------------------- 1 | --color 2 | -------------------------------------------------------------------------------- /spec/dummy/README.rdoc: -------------------------------------------------------------------------------- 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 | rake doc:app. 29 | -------------------------------------------------------------------------------- /spec/dummy/Rakefile: -------------------------------------------------------------------------------- 1 | # Add your own tasks in files placed in lib/tasks ending in .rake, 2 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. 3 | 4 | require File.expand_path('../config/application', __FILE__) 5 | 6 | Dummy::Application.load_tasks 7 | -------------------------------------------------------------------------------- /spec/dummy/app/assets/images/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chamnap/themes_on_rails/c03669a0ef9fd8b0cd38309a2cfdc6dfcc8c80da/spec/dummy/app/assets/images/.keep -------------------------------------------------------------------------------- /spec/dummy/app/assets/javascripts/application.js: -------------------------------------------------------------------------------- 1 | // This is a manifest file that'll be compiled into application.js, which will include all the files 2 | // listed below. 3 | // 4 | // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, 5 | // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path. 6 | // 7 | // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the 8 | // compiled file. 9 | // 10 | // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details 11 | // about supported directives. 12 | // 13 | //= require_tree . 14 | -------------------------------------------------------------------------------- /spec/dummy/app/assets/javascripts/posts.js: -------------------------------------------------------------------------------- 1 | // Place all the behaviors and hooks related to the matching controller here. 2 | // All this logic will automatically be available in application.js. 3 | -------------------------------------------------------------------------------- /spec/dummy/app/assets/stylesheets/application.css: -------------------------------------------------------------------------------- 1 | /* 2 | * This is a manifest file that'll be compiled into application.css, which will include all the files 3 | * listed below. 4 | * 5 | * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, 6 | * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path. 7 | * 8 | * You're free to add application-wide styles to this file and they'll appear at the top of the 9 | * compiled file, but it's generally better to create a new file per style scope. 10 | * 11 | *= require_self 12 | *= require_tree . 13 | */ 14 | -------------------------------------------------------------------------------- /spec/dummy/app/assets/stylesheets/posts.css: -------------------------------------------------------------------------------- 1 | /* 2 | Place all the styles related to the matching controller here. 3 | They will automatically be included in application.css. 4 | */ 5 | -------------------------------------------------------------------------------- /spec/dummy/app/assets/stylesheets/scaffold.css: -------------------------------------------------------------------------------- 1 | body { background-color: #fff; color: #333; } 2 | 3 | body, p, ol, ul, td { 4 | font-family: verdana, arial, helvetica, sans-serif; 5 | font-size: 13px; 6 | line-height: 18px; 7 | } 8 | 9 | pre { 10 | background-color: #eee; 11 | padding: 10px; 12 | font-size: 11px; 13 | } 14 | 15 | a { color: #000; } 16 | a:visited { color: #666; } 17 | a:hover { color: #fff; background-color:#000; } 18 | 19 | div.field, div.actions { 20 | margin-bottom: 10px; 21 | } 22 | 23 | #notice { 24 | color: green; 25 | } 26 | 27 | .field_with_errors { 28 | padding: 2px; 29 | background-color: red; 30 | display: table; 31 | } 32 | 33 | #error_explanation { 34 | width: 450px; 35 | border: 2px solid red; 36 | padding: 7px; 37 | padding-bottom: 0; 38 | margin-bottom: 20px; 39 | background-color: #f0f0f0; 40 | } 41 | 42 | #error_explanation h2 { 43 | text-align: left; 44 | font-weight: bold; 45 | padding: 5px 5px 5px 15px; 46 | font-size: 12px; 47 | margin: -7px; 48 | margin-bottom: 0px; 49 | background-color: #c00; 50 | color: #fff; 51 | } 52 | 53 | #error_explanation ul li { 54 | font-size: 12px; 55 | list-style: square; 56 | } 57 | -------------------------------------------------------------------------------- /spec/dummy/app/controllers/application_controller.rb: -------------------------------------------------------------------------------- 1 | class ApplicationController < ActionController::Base 2 | # Prevent CSRF attacks by raising an exception. 3 | # For APIs, you may want to use :null_session instead. 4 | protect_from_forgery with: :exception 5 | 6 | def default_url_options 7 | { theme: params[:theme] }.merge(super) 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /spec/dummy/app/controllers/concerns/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chamnap/themes_on_rails/c03669a0ef9fd8b0cd38309a2cfdc6dfcc8c80da/spec/dummy/app/controllers/concerns/.keep -------------------------------------------------------------------------------- /spec/dummy/app/controllers/posts_controller.rb: -------------------------------------------------------------------------------- 1 | class PostsController < ApplicationController 2 | theme :theme_resolver, except: [:new] 3 | 4 | if Rails::VERSION::MAJOR == 4 5 | before_action :set_post, only: [:show, :edit, :update, :destroy] 6 | else 7 | before_filter :set_post, only: [:show, :edit, :update, :destroy] 8 | end 9 | 10 | # GET /posts 11 | def index 12 | @posts = Post.all 13 | end 14 | 15 | # GET /posts/1 16 | def show 17 | end 18 | 19 | # GET /posts/new 20 | def new 21 | @post = Post.new 22 | end 23 | 24 | # GET /posts/1/edit 25 | def edit 26 | end 27 | 28 | # POST /posts 29 | def create 30 | @post = Post.new(post_params) 31 | 32 | if @post.save 33 | redirect_to @post, notice: 'Post was successfully created.' 34 | else 35 | render action: 'new' 36 | end 37 | end 38 | 39 | # PATCH/PUT /posts/1 40 | def update 41 | if @post.update(post_params) 42 | redirect_to @post, notice: 'Post was successfully updated.' 43 | else 44 | render action: 'edit' 45 | end 46 | end 47 | 48 | # DELETE /posts/1 49 | def destroy 50 | @post.destroy 51 | redirect_to posts_url, notice: 'Post was successfully destroyed.' 52 | end 53 | 54 | def get_theme 55 | render inline: "<%= current_theme %>" 56 | end 57 | 58 | private 59 | # Use callbacks to share common setup or constraints between actions. 60 | def set_post 61 | @post = Post.find(params[:id]) 62 | end 63 | 64 | # Only allow a trusted parameter "white list" through. 65 | def post_params 66 | params.require(:post).permit(:title, :description) 67 | end 68 | 69 | def theme_resolver 70 | params[:theme].presence || "theme_a" 71 | end 72 | end 73 | -------------------------------------------------------------------------------- /spec/dummy/app/helpers/application_helper.rb: -------------------------------------------------------------------------------- 1 | module ApplicationHelper 2 | end 3 | -------------------------------------------------------------------------------- /spec/dummy/app/helpers/posts_helper.rb: -------------------------------------------------------------------------------- 1 | module PostsHelper 2 | end 3 | -------------------------------------------------------------------------------- /spec/dummy/app/mailers/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chamnap/themes_on_rails/c03669a0ef9fd8b0cd38309a2cfdc6dfcc8c80da/spec/dummy/app/mailers/.keep -------------------------------------------------------------------------------- /spec/dummy/app/models/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chamnap/themes_on_rails/c03669a0ef9fd8b0cd38309a2cfdc6dfcc8c80da/spec/dummy/app/models/.keep -------------------------------------------------------------------------------- /spec/dummy/app/models/concerns/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chamnap/themes_on_rails/c03669a0ef9fd8b0cd38309a2cfdc6dfcc8c80da/spec/dummy/app/models/concerns/.keep -------------------------------------------------------------------------------- /spec/dummy/app/models/post.rb: -------------------------------------------------------------------------------- 1 | class Post < ActiveRecord::Base 2 | end 3 | -------------------------------------------------------------------------------- /spec/dummy/app/themes/theme_a/assets/images/theme_a/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chamnap/themes_on_rails/c03669a0ef9fd8b0cd38309a2cfdc6dfcc8c80da/spec/dummy/app/themes/theme_a/assets/images/theme_a/.gitkeep -------------------------------------------------------------------------------- /spec/dummy/app/themes/theme_a/assets/javascripts/theme_a/all.js: -------------------------------------------------------------------------------- 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 . -------------------------------------------------------------------------------- /spec/dummy/app/themes/theme_a/assets/stylesheets/theme_a/all.css: -------------------------------------------------------------------------------- 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 | */ -------------------------------------------------------------------------------- /spec/dummy/app/themes/theme_a/views/layouts/theme_a.html.haml: -------------------------------------------------------------------------------- 1 | !!! 2 | %html 3 | %head 4 | %title Theme A 5 | = stylesheet_link_tag "theme_a/all", media: "all", "data-turbolinks-track" => true 6 | = javascript_include_tag "theme_a/all", "data-turbolinks-track" => true 7 | = csrf_meta_tags 8 | %body 9 | = yield -------------------------------------------------------------------------------- /spec/dummy/app/themes/theme_a/views/posts/_form.html.erb: -------------------------------------------------------------------------------- 1 | <%= form_for(@post) do |f| %> 2 | <% if @post.errors.any? %> 3 |
4 |

<%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:

5 | 6 | 11 |
12 | <% end %> 13 | 14 |
15 | <%= f.label :title %>
16 | <%= f.text_field :title %> 17 |
18 |
19 | <%= f.label :description %>
20 | <%= f.text_area :description %> 21 |
22 |
23 | <%= f.submit %> 24 |
25 | <% end %> 26 | -------------------------------------------------------------------------------- /spec/dummy/app/themes/theme_a/views/posts/edit.html.erb: -------------------------------------------------------------------------------- 1 |

Editing post: theme_a

2 | 3 | <%= render 'form' %> 4 | 5 | <%= link_to 'Show', @post %> | 6 | <%= link_to 'Back', posts_path %> 7 | -------------------------------------------------------------------------------- /spec/dummy/app/themes/theme_a/views/posts/index.html.erb: -------------------------------------------------------------------------------- 1 |

Listing posts: theme_a

2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | <% @posts.each do |post| %> 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | <% end %> 24 | 25 |
TitleDescription
<%= post.title %><%= post.description %><%= link_to 'Show', post %><%= link_to 'Edit', edit_post_path(post) %><%= link_to 'Destroy', post, method: :delete, data: { confirm: 'Are you sure?' } %>
26 | 27 |
28 | 29 | <%= link_to 'New Post', new_post_path %> 30 | -------------------------------------------------------------------------------- /spec/dummy/app/themes/theme_a/views/posts/new.html.erb: -------------------------------------------------------------------------------- 1 |

New post: theme_a

2 | 3 | <%= render 'form' %> 4 | 5 | <%= link_to 'Back', posts_path %> 6 | -------------------------------------------------------------------------------- /spec/dummy/app/themes/theme_a/views/posts/show.html.erb: -------------------------------------------------------------------------------- 1 |

<%= notice %>

2 |

Post: <%= @post.id %> theme_a

3 | 4 |

5 | Title: 6 | <%= @post.title %> 7 |

8 | 9 |

10 | Description: 11 | <%= @post.description %> 12 |

13 | 14 | <%= link_to 'Edit', edit_post_path(@post) %> | 15 | <%= link_to 'Back', posts_path %> 16 | -------------------------------------------------------------------------------- /spec/dummy/app/themes/theme_b/assets/images/theme_b/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chamnap/themes_on_rails/c03669a0ef9fd8b0cd38309a2cfdc6dfcc8c80da/spec/dummy/app/themes/theme_b/assets/images/theme_b/.gitkeep -------------------------------------------------------------------------------- /spec/dummy/app/themes/theme_b/assets/javascripts/theme_b/all.js: -------------------------------------------------------------------------------- 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 . -------------------------------------------------------------------------------- /spec/dummy/app/themes/theme_b/assets/stylesheets/theme_b/all.css: -------------------------------------------------------------------------------- 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 | */ -------------------------------------------------------------------------------- /spec/dummy/app/themes/theme_b/views/layouts/alternate_theme_b.html.haml: -------------------------------------------------------------------------------- 1 | !!! 2 | %html 3 | %head 4 | %title Alternate Theme B 5 | = stylesheet_link_tag "theme_b/all", media: "all", "data-turbolinks-track" => true 6 | = javascript_include_tag "theme_b/all", "data-turbolinks-track" => true 7 | = csrf_meta_tags 8 | %body 9 | = yield -------------------------------------------------------------------------------- /spec/dummy/app/themes/theme_b/views/layouts/theme_b.html.haml: -------------------------------------------------------------------------------- 1 | !!! 2 | %html 3 | %head 4 | %title Theme B 5 | = stylesheet_link_tag "theme_b/all", media: "all", "data-turbolinks-track" => true 6 | = javascript_include_tag "theme_b/all", "data-turbolinks-track" => true 7 | = csrf_meta_tags 8 | %body 9 | = yield -------------------------------------------------------------------------------- /spec/dummy/app/themes/theme_b/views/posts/_form.html.erb: -------------------------------------------------------------------------------- 1 | <%= form_for(@post) do |f| %> 2 | <% if @post.errors.any? %> 3 |
4 |

<%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:

5 | 6 | 11 |
12 | <% end %> 13 | 14 |
15 | <%= f.label :title %>
16 | <%= f.text_field :title %> 17 |
18 |
19 | <%= f.label :description %>
20 | <%= f.text_area :description %> 21 |
22 |
23 | <%= f.submit %> 24 |
25 | <% end %> 26 | -------------------------------------------------------------------------------- /spec/dummy/app/themes/theme_b/views/posts/edit.html.erb: -------------------------------------------------------------------------------- 1 |

Editing post: theme_b

2 | 3 | <%= render 'form' %> 4 | 5 | <%= link_to 'Show', @post %> | 6 | <%= link_to 'Back', posts_path %> 7 | -------------------------------------------------------------------------------- /spec/dummy/app/themes/theme_b/views/posts/index.html.erb: -------------------------------------------------------------------------------- 1 |

Listing posts: theme_b

2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | <% @posts.each do |post| %> 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | <% end %> 24 | 25 |
TitleDescription
<%= post.title %><%= post.description %><%= link_to 'Show', post %><%= link_to 'Edit', edit_post_path(post) %><%= link_to 'Destroy', post, method: :delete, data: { confirm: 'Are you sure?' } %>
26 | 27 |
28 | 29 | <%= link_to 'New Post', new_post_path %> -------------------------------------------------------------------------------- /spec/dummy/app/themes/theme_b/views/posts/new.html.erb: -------------------------------------------------------------------------------- 1 |

New post: theme_b

2 | 3 | <%= render 'form' %> 4 | 5 | <%= link_to 'Back', posts_path %> 6 | -------------------------------------------------------------------------------- /spec/dummy/app/themes/theme_b/views/posts/show.html.erb: -------------------------------------------------------------------------------- 1 |

<%= notice %>

2 |

Post: <%= @post.id %> theme_b

3 | 4 |

5 | Title: 6 | <%= @post.title %> 7 |

8 | 9 |

10 | Description: 11 | <%= @post.description %> 12 |

13 | 14 | <%= link_to 'Edit', edit_post_path(@post) %> | 15 | <%= link_to 'Back', posts_path %> 16 | -------------------------------------------------------------------------------- /spec/dummy/app/themes/theme_c/assets/images/theme_c/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chamnap/themes_on_rails/c03669a0ef9fd8b0cd38309a2cfdc6dfcc8c80da/spec/dummy/app/themes/theme_c/assets/images/theme_c/.gitkeep -------------------------------------------------------------------------------- /spec/dummy/app/themes/theme_c/assets/images/theme_c/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chamnap/themes_on_rails/c03669a0ef9fd8b0cd38309a2cfdc6dfcc8c80da/spec/dummy/app/themes/theme_c/assets/images/theme_c/1.jpg -------------------------------------------------------------------------------- /spec/dummy/app/themes/theme_c/assets/javascripts/theme_c/all.js: -------------------------------------------------------------------------------- 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 . -------------------------------------------------------------------------------- /spec/dummy/app/themes/theme_c/assets/stylesheets/theme_c/all.css: -------------------------------------------------------------------------------- 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 | */ -------------------------------------------------------------------------------- /spec/dummy/app/themes/theme_c/locales/en.yml: -------------------------------------------------------------------------------- 1 | en: 2 | theme_c: 3 | links: 4 | home: 'Home' -------------------------------------------------------------------------------- /spec/dummy/app/themes/theme_c/locales/km.yml: -------------------------------------------------------------------------------- 1 | km: 2 | theme_c: 3 | links: 4 | home: 'ទំព័រដើម' -------------------------------------------------------------------------------- /spec/dummy/app/themes/theme_c/views/layouts/theme_c.liquid: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Theme C 5 | 6 | 7 | 8 | 9 | {{ content_for_layout }} 10 | 11 | -------------------------------------------------------------------------------- /spec/dummy/app/themes/theme_c/views/posts/_partial.liquid: -------------------------------------------------------------------------------- 1 | Theme_C_Partial -------------------------------------------------------------------------------- /spec/dummy/app/themes/theme_c/views/posts/index.liquid: -------------------------------------------------------------------------------- 1 |

Listing posts: theme_c

2 | 3 | {% include 'partial' %} -------------------------------------------------------------------------------- /spec/dummy/app/views/layouts/application.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Dummy 5 | <%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %> 6 | <%= javascript_include_tag "application", "data-turbolinks-track" => true %> 7 | <%= csrf_meta_tags %> 8 | 9 | 10 | 11 | <%= yield %> 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /spec/dummy/app/views/posts/_form.html.erb: -------------------------------------------------------------------------------- 1 | <%= form_for(@post) do |f| %> 2 | <% if @post.errors.any? %> 3 |
4 |

<%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:

5 | 6 | 11 |
12 | <% end %> 13 | 14 |
15 | <%= f.label :title %>
16 | <%= f.text_field :title %> 17 |
18 |
19 | <%= f.label :description %>
20 | <%= f.text_area :description %> 21 |
22 |
23 | <%= f.submit %> 24 |
25 | <% end %> 26 | -------------------------------------------------------------------------------- /spec/dummy/app/views/posts/edit.html.erb: -------------------------------------------------------------------------------- 1 |

Editing post

2 | 3 | <%= render 'form' %> 4 | 5 | <%= link_to 'Show', @post %> | 6 | <%= link_to 'Back', posts_path %> 7 | -------------------------------------------------------------------------------- /spec/dummy/app/views/posts/index.html.erb: -------------------------------------------------------------------------------- 1 |

Listing posts

2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | <% @posts.each do |post| %> 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | <% end %> 24 | 25 |
TitleDescription
<%= post.title %><%= post.description %><%= link_to 'Show', post %><%= link_to 'Edit', edit_post_path(post) %><%= link_to 'Destroy', post, method: :delete, data: { confirm: 'Are you sure?' } %>
26 | 27 |
28 | 29 | <%= link_to 'New Post', new_post_path %> 30 | -------------------------------------------------------------------------------- /spec/dummy/app/views/posts/new.html.erb: -------------------------------------------------------------------------------- 1 |

New post

2 | 3 | <%= render 'form' %> 4 | 5 | <%= link_to 'Back', posts_path %> 6 | -------------------------------------------------------------------------------- /spec/dummy/app/views/posts/show.html.erb: -------------------------------------------------------------------------------- 1 |

<%= notice %>

2 | 3 |

4 | Title: 5 | <%= @post.title %> 6 |

7 | 8 |

9 | Description: 10 | <%= @post.description %> 11 |

12 | 13 | <%= link_to 'Edit', edit_post_path(@post) %> | 14 | <%= link_to 'Back', posts_path %> 15 | -------------------------------------------------------------------------------- /spec/dummy/bin/bundle: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) 3 | load Gem.bin_path('bundler', 'bundle') 4 | -------------------------------------------------------------------------------- /spec/dummy/bin/rails: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | APP_PATH = File.expand_path('../../config/application', __FILE__) 3 | require_relative '../config/boot' 4 | require 'rails/commands' 5 | -------------------------------------------------------------------------------- /spec/dummy/bin/rake: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require_relative '../config/boot' 3 | require 'rake' 4 | Rake.application.run 5 | -------------------------------------------------------------------------------- /spec/dummy/config.ru: -------------------------------------------------------------------------------- 1 | # This file is used by Rack-based servers to start the application. 2 | 3 | require ::File.expand_path('../config/environment', __FILE__) 4 | run Rails.application 5 | -------------------------------------------------------------------------------- /spec/dummy/config/application.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../boot', __FILE__) 2 | 3 | require 'rails/all' 4 | 5 | Bundler.require(*Rails.groups) 6 | require "themes_on_rails" 7 | 8 | module Dummy 9 | class Application < Rails::Application 10 | # Settings in config/environments/* take precedence over those specified here. 11 | # Application configuration should go into files in config/initializers 12 | # -- all .rb files in that directory are automatically loaded. 13 | 14 | # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. 15 | # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. 16 | # config.time_zone = 'Central Time (US & Canada)' 17 | 18 | # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. 19 | # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] 20 | # config.i18n.default_locale = :de 21 | end 22 | end -------------------------------------------------------------------------------- /spec/dummy/config/boot.rb: -------------------------------------------------------------------------------- 1 | # Set up gems listed in the Gemfile. 2 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__) 3 | 4 | require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE']) 5 | $LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__) 6 | -------------------------------------------------------------------------------- /spec/dummy/config/database.yml: -------------------------------------------------------------------------------- 1 | # SQLite version 3.x 2 | # gem install sqlite3 3 | # 4 | # Ensure the SQLite 3 gem is defined in your Gemfile 5 | # gem 'sqlite3' 6 | development: 7 | adapter: sqlite3 8 | database: db/development.sqlite3 9 | pool: 5 10 | timeout: 5000 11 | 12 | # Warning: The database defined as "test" will be erased and 13 | # re-generated from your development database when you run "rake". 14 | # Do not set this db to the same as development or production. 15 | test: 16 | adapter: sqlite3 17 | database: db/test.sqlite3 18 | pool: 5 19 | timeout: 5000 20 | 21 | production: 22 | adapter: sqlite3 23 | database: db/production.sqlite3 24 | pool: 5 25 | timeout: 5000 26 | -------------------------------------------------------------------------------- /spec/dummy/config/environment.rb: -------------------------------------------------------------------------------- 1 | # Load the Rails application. 2 | require File.expand_path('../application', __FILE__) 3 | 4 | # Initialize the Rails application. 5 | Dummy::Application.initialize! 6 | -------------------------------------------------------------------------------- /spec/dummy/config/environments/development.rb: -------------------------------------------------------------------------------- 1 | Dummy::Application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb. 3 | 4 | # In the development environment your application's code is reloaded on 5 | # every request. This slows down response time but is perfect for development 6 | # since you don't have to restart the web server when you make code changes. 7 | config.cache_classes = false 8 | 9 | # Do not eager load code on boot. 10 | config.eager_load = false 11 | 12 | # Show full error reports and disable caching. 13 | config.consider_all_requests_local = true 14 | config.action_controller.perform_caching = false 15 | 16 | # Don't care if the mailer can't send. 17 | config.action_mailer.raise_delivery_errors = false 18 | 19 | # Print deprecation notices to the Rails logger. 20 | config.active_support.deprecation = :log 21 | 22 | # Raise an error on page load if there are pending migrations 23 | config.active_record.migration_error = :page_load 24 | 25 | # Debug mode disables concatenation and preprocessing of assets. 26 | # This option may cause significant delays in view rendering with a large 27 | # number of complex assets. 28 | config.assets.debug = true 29 | end 30 | -------------------------------------------------------------------------------- /spec/dummy/config/environments/production.rb: -------------------------------------------------------------------------------- 1 | Dummy::Application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb. 3 | 4 | # Code is not reloaded between requests. 5 | config.cache_classes = true 6 | 7 | # Eager load code on boot. This eager loads most of Rails and 8 | # your application in memory, allowing both thread web servers 9 | # and those relying on copy on write to perform better. 10 | # Rake tasks automatically ignore this option for performance. 11 | config.eager_load = true 12 | 13 | # Full error reports are disabled and caching is turned on. 14 | config.consider_all_requests_local = false 15 | config.action_controller.perform_caching = true 16 | 17 | # Enable Rack::Cache to put a simple HTTP cache in front of your application 18 | # Add `rack-cache` to your Gemfile before enabling this. 19 | # For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid. 20 | # config.action_dispatch.rack_cache = true 21 | 22 | # Disable Rails's static asset server (Apache or nginx will already do this). 23 | config.serve_static_files = false 24 | 25 | # Compress JavaScripts and CSS. 26 | config.assets.js_compressor = :uglifier 27 | # config.assets.css_compressor = :sass 28 | 29 | # Do not fallback to assets pipeline if a precompiled asset is missed. 30 | config.assets.compile = false 31 | 32 | # Generate digests for assets URLs. 33 | config.assets.digest = true 34 | 35 | # Version of your assets, change this if you want to expire all your assets. 36 | config.assets.version = '1.0' 37 | 38 | # Specifies the header that your server uses for sending files. 39 | # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache 40 | # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx 41 | 42 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. 43 | # config.force_ssl = true 44 | 45 | # Set to :debug to see everything in the log. 46 | config.log_level = :info 47 | 48 | # Prepend all log lines with the following tags. 49 | # config.log_tags = [ :subdomain, :uuid ] 50 | 51 | # Use a different logger for distributed setups. 52 | # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) 53 | 54 | # Use a different cache store in production. 55 | # config.cache_store = :mem_cache_store 56 | 57 | # Enable serving of images, stylesheets, and JavaScripts from an asset server. 58 | # config.action_controller.asset_host = "http://assets.example.com" 59 | 60 | # Precompile additional assets. 61 | # application.js, application.css, and all non-JS/CSS in app/assets folder are already added. 62 | # config.assets.precompile += %w( search.js ) 63 | 64 | # Ignore bad email addresses and do not raise email delivery errors. 65 | # Set this to true and configure the email server for immediate delivery to raise delivery errors. 66 | # config.action_mailer.raise_delivery_errors = false 67 | 68 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to 69 | # the I18n.default_locale when a translation can not be found). 70 | config.i18n.fallbacks = true 71 | 72 | # Send deprecation notices to registered listeners. 73 | config.active_support.deprecation = :notify 74 | 75 | # Disable automatic flushing of the log to improve performance. 76 | # config.autoflush_log = false 77 | 78 | # Use default logging formatter so that PID and timestamp are not suppressed. 79 | config.log_formatter = ::Logger::Formatter.new 80 | end 81 | -------------------------------------------------------------------------------- /spec/dummy/config/environments/test.rb: -------------------------------------------------------------------------------- 1 | Dummy::Application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb. 3 | 4 | # The test environment is used exclusively to run your application's 5 | # test suite. You never need to work with it otherwise. Remember that 6 | # your test database is "scratch space" for the test suite and is wiped 7 | # and recreated between test runs. Don't rely on the data there! 8 | config.cache_classes = true 9 | 10 | # Do not eager load code on boot. This avoids loading your whole application 11 | # just for the purpose of running a single test. If you are using a tool that 12 | # preloads Rails for running tests, you may have to set it to true. 13 | config.eager_load = false 14 | 15 | # Configure static asset server for tests with Cache-Control for performance. 16 | config.serve_static_files = true 17 | config.static_cache_control = "public, max-age=3600" 18 | 19 | # Show full error reports and disable caching. 20 | config.consider_all_requests_local = true 21 | config.action_controller.perform_caching = false 22 | 23 | # Raise exceptions instead of rendering exception templates. 24 | config.action_dispatch.show_exceptions = false 25 | 26 | # Disable request forgery protection in test environment. 27 | config.action_controller.allow_forgery_protection = false 28 | 29 | # Tell Action Mailer not to deliver emails to the real world. 30 | # The :test delivery method accumulates sent emails in the 31 | # ActionMailer::Base.deliveries array. 32 | config.action_mailer.delivery_method = :test 33 | 34 | # Print deprecation notices to the stderr. 35 | config.active_support.deprecation = :stderr 36 | end 37 | -------------------------------------------------------------------------------- /spec/dummy/config/initializers/backtrace_silencers.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. 4 | # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } 5 | 6 | # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. 7 | # Rails.backtrace_cleaner.remove_silencers! 8 | -------------------------------------------------------------------------------- /spec/dummy/config/initializers/filter_parameter_logging.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Configure sensitive parameters which will be filtered from the log file. 4 | Rails.application.config.filter_parameters += [:password] 5 | -------------------------------------------------------------------------------- /spec/dummy/config/initializers/inflections.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new inflection rules using the following format. Inflections 4 | # are locale specific, and you may define rules for as many different 5 | # locales as you wish. All of these examples are active by default: 6 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 7 | # inflect.plural /^(ox)$/i, '\1en' 8 | # inflect.singular /^(ox)en/i, '\1' 9 | # inflect.irregular 'person', 'people' 10 | # inflect.uncountable %w( fish sheep ) 11 | # end 12 | 13 | # These inflection rules are supported but not enabled by default: 14 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 15 | # inflect.acronym 'RESTful' 16 | # end 17 | -------------------------------------------------------------------------------- /spec/dummy/config/initializers/mime_types.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new mime types for use in respond_to blocks: 4 | # Mime::Type.register "text/richtext", :rtf 5 | # Mime::Type.register_alias "text/html", :iphone 6 | -------------------------------------------------------------------------------- /spec/dummy/config/initializers/secret_token.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Your secret key is used for verifying the integrity of signed cookies. 4 | # If you change this key, all old signed cookies will become invalid! 5 | 6 | # Make sure the secret is at least 30 characters and all random, 7 | # no regular words or you'll be exposed to dictionary attacks. 8 | # You can use `rake secret` to generate a secure secret key. 9 | 10 | # Make sure your secret_key_base is kept private 11 | # if you're sharing your code publicly. 12 | Dummy::Application.config.secret_key_base = 'ee6d27b27f2b943a0babc187f675411fbfbf8444d530071395cb11b18e748b40a56956fcdf5262709dda326397c1fef182d89c00d8f959ac295887d5a0d1c88c' 13 | -------------------------------------------------------------------------------- /spec/dummy/config/initializers/session_store.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | Dummy::Application.config.session_store :cookie_store, key: '_dummy_session' 4 | -------------------------------------------------------------------------------- /spec/dummy/config/initializers/wrap_parameters.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # This file contains settings for ActionController::ParamsWrapper which 4 | # is enabled by default. 5 | 6 | # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. 7 | ActiveSupport.on_load(:action_controller) do 8 | wrap_parameters format: [:json] if respond_to?(:wrap_parameters) 9 | end 10 | 11 | # To enable root element in JSON for ActiveRecord objects. 12 | # ActiveSupport.on_load(:active_record) do 13 | # self.include_root_in_json = true 14 | # end 15 | -------------------------------------------------------------------------------- /spec/dummy/config/locales/en.yml: -------------------------------------------------------------------------------- 1 | # Files in the config/locales directory are used for internationalization 2 | # and are automatically loaded by Rails. If you want to use locales other 3 | # than English, add the necessary files in this directory. 4 | # 5 | # To use the locales, use `I18n.t`: 6 | # 7 | # I18n.t 'hello' 8 | # 9 | # In views, this is aliased to just `t`: 10 | # 11 | # <%= t('hello') %> 12 | # 13 | # To use a different locale, set it with `I18n.locale`: 14 | # 15 | # I18n.locale = :es 16 | # 17 | # This would use the information in config/locales/es.yml. 18 | # 19 | # To learn more, please read the Rails Internationalization guide 20 | # available at http://guides.rubyonrails.org/i18n.html. 21 | 22 | en: 23 | hello: "Hello world" 24 | -------------------------------------------------------------------------------- /spec/dummy/config/routes.rb: -------------------------------------------------------------------------------- 1 | Dummy::Application.routes.draw do 2 | resources :posts do 3 | get :get_theme, on: :collection 4 | end 5 | 6 | # The priority is based upon order of creation: first created -> highest priority. 7 | # See how all your routes lay out with "rake routes". 8 | 9 | # You can have the root of your site routed with "root" 10 | # root 'welcome#index' 11 | 12 | # Example of regular route: 13 | # get 'products/:id' => 'catalog#view' 14 | 15 | # Example of named route that can be invoked with purchase_url(id: product.id) 16 | # get 'products/:id/purchase' => 'catalog#purchase', as: :purchase 17 | 18 | # Example resource route (maps HTTP verbs to controller actions automatically): 19 | # resources :products 20 | 21 | # Example resource route with options: 22 | # resources :products do 23 | # member do 24 | # get 'short' 25 | # post 'toggle' 26 | # end 27 | # 28 | # collection do 29 | # get 'sold' 30 | # end 31 | # end 32 | 33 | # Example resource route with sub-resources: 34 | # resources :products do 35 | # resources :comments, :sales 36 | # resource :seller 37 | # end 38 | 39 | # Example resource route with more complex sub-resources: 40 | # resources :products do 41 | # resources :comments 42 | # resources :sales do 43 | # get 'recent', on: :collection 44 | # end 45 | # end 46 | 47 | # Example resource route with concerns: 48 | # concern :toggleable do 49 | # post 'toggle' 50 | # end 51 | # resources :posts, concerns: :toggleable 52 | # resources :photos, concerns: :toggleable 53 | 54 | # Example resource route within a namespace: 55 | # namespace :admin do 56 | # # Directs /admin/products/* to Admin::ProductsController 57 | # # (app/controllers/admin/products_controller.rb) 58 | # resources :products 59 | # end 60 | end 61 | -------------------------------------------------------------------------------- /spec/dummy/db/migrate/20131120082307_create_posts.rb: -------------------------------------------------------------------------------- 1 | class CreatePosts < ActiveRecord::Migration 2 | def change 3 | create_table :posts do |t| 4 | t.string :title 5 | t.text :description 6 | 7 | t.timestamps 8 | end 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /spec/dummy/db/schema.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | # This file is auto-generated from the current state of the database. Instead 3 | # of editing this file, please use the migrations feature of Active Record to 4 | # incrementally modify your database, and then regenerate this schema definition. 5 | # 6 | # Note that this schema.rb definition is the authoritative source for your 7 | # database schema. If you need to create the application database on another 8 | # system, you should be using db:schema:load, not running all the migrations 9 | # from scratch. The latter is a flawed and unsustainable approach (the more migrations 10 | # you'll amass, the slower it'll run and the greater likelihood for issues). 11 | # 12 | # It's strongly recommended to check this file into your version control system. 13 | 14 | ActiveRecord::Schema.define(:version => 20131120082307) do 15 | 16 | create_table "posts", :force => true do |t| 17 | t.string "title" 18 | t.text "description" 19 | t.datetime "created_at" 20 | t.datetime "updated_at" 21 | end 22 | 23 | end 24 | -------------------------------------------------------------------------------- /spec/dummy/lib/assets/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chamnap/themes_on_rails/c03669a0ef9fd8b0cd38309a2cfdc6dfcc8c80da/spec/dummy/lib/assets/.keep -------------------------------------------------------------------------------- /spec/dummy/log/.keep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chamnap/themes_on_rails/c03669a0ef9fd8b0cd38309a2cfdc6dfcc8c80da/spec/dummy/log/.keep -------------------------------------------------------------------------------- /spec/dummy/public/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The page you were looking for doesn't exist (404) 5 | 48 | 49 | 50 | 51 | 52 |
53 |

The page you were looking for doesn't exist.

54 |

You may have mistyped the address or the page may have moved.

55 |
56 |

If you are the application owner check the logs for more information.

57 | 58 | 59 | -------------------------------------------------------------------------------- /spec/dummy/public/422.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The change you wanted was rejected (422) 5 | 48 | 49 | 50 | 51 | 52 |
53 |

The change you wanted was rejected.

54 |

Maybe you tried to change something you didn't have access to.

55 |
56 |

If you are the application owner check the logs for more information.

57 | 58 | 59 | -------------------------------------------------------------------------------- /spec/dummy/public/500.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | We're sorry, but something went wrong (500) 5 | 48 | 49 | 50 | 51 | 52 |
53 |

We're sorry, but something went wrong.

54 |
55 |

If you are the application owner check the logs for more information.

56 | 57 | 58 | -------------------------------------------------------------------------------- /spec/dummy/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chamnap/themes_on_rails/c03669a0ef9fd8b0cd38309a2cfdc6dfcc8c80da/spec/dummy/public/favicon.ico -------------------------------------------------------------------------------- /spec/dummy/spec/controllers/posts_controller_spec.rb: -------------------------------------------------------------------------------- 1 | require "spec_helper" 2 | 3 | describe PostsController do 4 | render_views 5 | 6 | context "theme :theme_b" do 7 | it "renders with provided theme :theme_b" do 8 | get :index, theme: "theme_b" 9 | 10 | expect(response.body).to match(/

Listing posts: theme_b<\/h1>/) 11 | end 12 | 13 | it "renders with layout :theme_b" do 14 | get :index, theme: "theme_b" 15 | 16 | expect(response).to render_template("layouts/theme_b") 17 | end 18 | end 19 | 20 | context "theme :theme_a" do 21 | it "renders with provided theme :theme_a" do 22 | get :index, theme: "theme_a" 23 | 24 | expect(response.body).to match(/

Listing posts: theme_a<\/h1>/) 25 | end 26 | 27 | it "renders with layout :theme_a" do 28 | get :index, theme: "theme_a" 29 | 30 | expect(response).to render_template("layouts/theme_a") 31 | end 32 | end 33 | 34 | context "theme :theme_c" do 35 | it "renders with provided theme :theme_c" do 36 | get :index, theme: "theme_c" 37 | 38 | expect(response.body).to match(/

Listing posts: theme_c<\/h1>/) 39 | end 40 | 41 | it "renders with layout :theme_c" do 42 | get :index, theme: "theme_c" 43 | 44 | expect(response).to render_template("layouts/theme_c") 45 | end 46 | 47 | it "renders with partial" do 48 | get :index, theme: "theme_c" 49 | 50 | expect(response.body).to match(/Theme_C_Partial/) 51 | end 52 | end 53 | 54 | context "default views" do 55 | it "renders with default views" do 56 | get :new, theme: "theme_a" 57 | 58 | expect(response.body).to match(/

New post<\/h1>/) 59 | end 60 | 61 | it "renders with layout :theme_a" do 62 | get :new, theme: "theme_a" 63 | 64 | expect(response).to render_template("layouts/application") 65 | end 66 | end 67 | 68 | context 'current theme' do 69 | it 'get current theme' do 70 | get :index, theme: "theme_a" 71 | expect(controller.current_theme).to eq "theme_a" 72 | end 73 | 74 | it 'renders with helper method' do 75 | get :get_theme, theme: "theme_a" 76 | expect(response.body).to eq "theme_a" 77 | end 78 | end 79 | 80 | end 81 | -------------------------------------------------------------------------------- /spec/dummy/spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | # This file is copied to spec/ when you run 'rails generate rspec:install' 2 | ENV["RAILS_ENV"] ||= 'test' 3 | require File.expand_path("../../config/environment", __FILE__) 4 | require 'rspec/rails' 5 | require 'rspec/autorun' 6 | 7 | # Requires supporting ruby files with custom matchers and macros, etc, 8 | # in spec/support/ and its subdirectories. 9 | Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f } 10 | 11 | # Checks for pending migrations before tests are run. 12 | # If you are not using ActiveRecord, you can remove this line. 13 | ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration) 14 | 15 | RSpec.configure do |config| 16 | # ## Mock Framework 17 | # 18 | # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line: 19 | # 20 | # config.mock_with :mocha 21 | # config.mock_with :flexmock 22 | # config.mock_with :rr 23 | 24 | # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures 25 | config.fixture_path = "#{::Rails.root}/spec/fixtures" 26 | 27 | # If you're not using ActiveRecord, or you'd prefer not to run each of your 28 | # examples within a transaction, remove the following line or assign false 29 | # instead of true. 30 | config.use_transactional_fixtures = true 31 | 32 | # If true, the base class of anonymous controllers will be inferred 33 | # automatically. This will be the default behavior in future versions of 34 | # rspec-rails. 35 | config.infer_base_class_for_anonymous_controllers = false 36 | 37 | # Run specs in random order to surface order dependencies. If you find an 38 | # order dependency and want to debug it, you can fix the order by providing 39 | # the seed, which is printed after each run. 40 | # --seed 1234 41 | config.order = "random" 42 | config.run_all_when_everything_filtered = true 43 | config.treat_symbols_as_metadata_keys_with_true_values = true 44 | end 45 | -------------------------------------------------------------------------------- /spec/generators/themes_on_rails/theme_generator_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | # Generators are not automatically loaded by Rails 4 | require 'generators/themes_on_rails/theme_generator' 5 | 6 | describe ThemesOnRails::Generators::ThemeGenerator do 7 | # Tell the generator where to put its output (what it thinks of as Rails.root) 8 | destination File.expand_path("../../../../../spec/dummy/tmp", __FILE__) 9 | 10 | before do 11 | prepare_destination 12 | run_generator %w(theme_a) 13 | end 14 | 15 | it "exists `app/themes`" do 16 | expect(file("app/themes")).to exist 17 | end 18 | 19 | it "exists `app/themes/theme_a`" do 20 | expect(file("app/themes/theme_a")).to exist 21 | end 22 | 23 | it "exists `app/themes/theme_a/locales`" do 24 | expect(file("app/themes/theme_a/locales")).to exist 25 | end 26 | 27 | it "exists `app/themes/theme_a/assets/images/theme_a`" do 28 | expect(file("app/themes/theme_a/assets/images/theme_a")).to exist 29 | end 30 | 31 | it "exists `app/themes/theme_a/assets/javascripts/theme_a`" do 32 | expect(file("app/themes/theme_a/assets/javascripts/theme_a")).to exist 33 | end 34 | 35 | it "exists `app/themes/theme_a/assets/javascripts/theme_a/all.js`" do 36 | expect(file("app/themes/theme_a/assets/javascripts/theme_a/all.js")).to exist 37 | end 38 | 39 | it "exists `app/themes/theme_a/assets/stylesheets/theme_a`" do 40 | expect(file("app/themes/theme_a/assets/stylesheets/theme_a")).to exist 41 | end 42 | 43 | it "exists `app/themes/theme_a/assets/stylesheets/theme_a/all.css`" do 44 | expect(file("app/themes/theme_a/assets/stylesheets/theme_a/all.css")).to exist 45 | end 46 | 47 | context "layout file: erb" do 48 | before(:all) { 49 | Rails.configuration.app_generators.rails[:template_engine] = :erb 50 | } 51 | after(:all) { 52 | Rails.configuration.app_generators.rails[:template_engine] = :haml 53 | } 54 | subject { file("app/themes/theme_a/views/layouts/theme_a.html.erb") } 55 | 56 | it { should exist } 57 | it { should contain(/\= stylesheet_link_tag \"theme_a\/all\"/) } 58 | it { should contain(/\= javascript_include_tag \"theme_a\/all\"/) } 59 | end 60 | 61 | context "layout file: haml" do 62 | before(:all) { 63 | Rails.configuration.app_generators.rails[:template_engine] = :haml 64 | } 65 | subject { file("app/themes/theme_a/views/layouts/theme_a.html.haml") } 66 | 67 | it { should exist } 68 | it { should contain(/\= stylesheet_link_tag \"theme_a\/all\"/) } 69 | it { should contain(/\= javascript_include_tag \"theme_a\/all\"/) } 70 | end 71 | 72 | context "layout file: liquid" do 73 | before(:all) { 74 | Rails.configuration.app_generators.rails[:template_engine] = :liquid 75 | } 76 | after(:all) { 77 | Rails.configuration.app_generators.rails[:template_engine] = :haml 78 | } 79 | subject { file("app/themes/theme_a/views/layouts/theme_a.liquid") } 80 | 81 | it { should exist } 82 | it { should contain(/\{\{ \'theme_a\/all\' | asset_path | javascript_include_tag \}\}/) } 83 | it { should contain(/\{\{ \'theme_a\/all\' | asset_path | stylesheet_link_tag \}\}/) } 84 | it { should contain(/\{\{ content_for_layout \}\}/) } 85 | end 86 | end -------------------------------------------------------------------------------- /spec/lib/action_controller_spec.rb: -------------------------------------------------------------------------------- 1 | require "spec_helper" 2 | 3 | describe ThemesOnRails::ActionController do 4 | let(:controller) { controller_class.new } 5 | let(:controller_class) { Class.new } 6 | 7 | it "initializes with theme as string" do 8 | action_controller = ThemesOnRails::ActionController.new(controller, "theme_a") 9 | 10 | expect(action_controller.theme_name).to eq("theme_a") 11 | end 12 | 13 | it "initializes with theme as symbol method" do 14 | def controller.theme_resolver 15 | "theme_a" 16 | end 17 | action_controller = ThemesOnRails::ActionController.new(controller, :theme_resolver) 18 | 19 | expect(action_controller.theme_name).to eq("theme_a") 20 | end 21 | 22 | it "initializes with theme as symbol" do 23 | action_controller = ThemesOnRails::ActionController.new(controller, :theme_a) 24 | 25 | expect(action_controller.theme_name).to eq("theme_a") 26 | end 27 | 28 | it "initializes with theme as proc or lambda" do 29 | action_controller = ThemesOnRails::ActionController.new(controller, lambda { |con| "theme_a" }) 30 | 31 | expect(action_controller.theme_name).to eq("theme_a") 32 | end 33 | 34 | it "initializes with theme as nil" do 35 | expect { 36 | ThemesOnRails::ActionController.new(controller, nil) 37 | }.to raise_error(ArgumentError) 38 | end 39 | 40 | it "#theme_view_path" do 41 | action_controller = ThemesOnRails::ActionController.new(controller, "theme_a") 42 | 43 | expect(action_controller.theme_view_path).to eq("#{Rails.root}/app/themes/theme_a/views") 44 | end 45 | end -------------------------------------------------------------------------------- /spec/lib/controller_additions_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe ThemesOnRails::ControllerAdditions do 4 | let(:controller_class) { Class.new } 5 | let(:controller) { controller_class.new } 6 | 7 | before do 8 | controller_class.send(:include, ThemesOnRails::ControllerAdditions) 9 | end 10 | 11 | it "invokes #apply_theme without options" do 12 | expect(ThemesOnRails::ActionController).to receive(:apply_theme).with(controller_class, "theme_a", {}) 13 | 14 | controller_class.theme "theme_a" 15 | end 16 | 17 | it "invokes #apply_theme with options" do 18 | expect(ThemesOnRails::ActionController).to receive(:apply_theme).with(controller_class, :theme_resolver, { only: [:show] }) 19 | 20 | controller_class.theme :theme_resolver, only: [:show] 21 | end 22 | end -------------------------------------------------------------------------------- /spec/lib/engine_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe ThemesOnRails::Engine do 4 | context 'assets.paths' do 5 | it 'includes `theme_a`: images, javascripts, stylesheets' do 6 | expect(Rails.application.config.assets.paths.to_s).to match(/theme_a\/assets\/images/) 7 | expect(Rails.application.config.assets.paths.to_s).to match(/theme_a\/assets\/javascripts/) 8 | expect(Rails.application.config.assets.paths.to_s).to match(/theme_a\/assets\/stylesheets/) 9 | end 10 | 11 | it 'includes `theme_b`: images, javascripts, stylesheets' do 12 | expect(Rails.application.config.assets.paths.to_s).to match(/theme_b\/assets\/images/) 13 | expect(Rails.application.config.assets.paths.to_s).to match(/theme_b\/assets\/javascripts/) 14 | expect(Rails.application.config.assets.paths.to_s).to match(/theme_b\/assets\/stylesheets/) 15 | end 16 | end 17 | 18 | context 'i18n.load_path' do 19 | it 'includes `theme_c`: locales' do 20 | expect(Rails.application.config.i18n.load_path.to_s).to match(/theme_c\/locales\/en.yml/) 21 | expect(Rails.application.config.i18n.load_path.to_s).to match(/theme_c\/locales\/km.yml/) 22 | end 23 | end 24 | end -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | if ENV['COVERAGE'] || ENV['CI'] 2 | require 'coveralls' 3 | require 'simplecov' 4 | SimpleCov.add_filter 'spec' 5 | SimpleCov.add_filter 'gemfiles' 6 | Coveralls.wear! 7 | end 8 | 9 | # Configure Rails Environment 10 | ENV["RAILS_ENV"] = "test" 11 | 12 | require File.expand_path("../dummy/config/environment.rb", __FILE__) 13 | require "themes_on_rails" 14 | require "rspec/rails" 15 | require "ammeter/init" 16 | Rails.backtrace_cleaner.remove_silencers! 17 | 18 | # Load support files 19 | Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f } 20 | 21 | RSpec.configure do |config| 22 | config.filter_run focus: true 23 | config.run_all_when_everything_filtered = true 24 | config.infer_spec_type_from_file_location! 25 | end 26 | -------------------------------------------------------------------------------- /themes_on_rails.gemspec: -------------------------------------------------------------------------------- 1 | $:.push File.expand_path("../lib", __FILE__) 2 | 3 | # Maintain your gem's version: 4 | require "themes_on_rails/version" 5 | 6 | # Describe your gem and declare its dependencies: 7 | Gem::Specification.new do |s| 8 | s.name = "themes_on_rails" 9 | s.version = ThemesOnRails::VERSION 10 | s.authors = ["Chamnap Chhorn"] 11 | s.email = ["chamnapchhorn@gmail.com"] 12 | s.homepage = "https://github.com/chamnap/themes_on_rails" 13 | s.summary = "Adds multi themes support to your Rails 3/4 application" 14 | s.description = "Adds multi themes support to your Rails 3/4 application" 15 | s.license = "MIT" 16 | 17 | s.required_ruby_version = '>= 2.0.0' 18 | s.required_rubygems_version = '>= 1.8.11' 19 | 20 | s.files = Dir["{app,config,db,lib}/**/*"] + ["MIT-LICENSE", "Rakefile", "README.md"] 21 | s.test_files = Dir["spec/**/*"] 22 | s.require_paths = ["lib"] 23 | 24 | s.add_dependency "rails", ">= 3.2" 25 | s.add_development_dependency "ammeter", "~> 1.1.2" 26 | s.add_development_dependency "bundler", "~> 1.11" 27 | end 28 | --------------------------------------------------------------------------------