themes_for_rails 0.4.3 → 0.5.0.pre
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/.travis.yml +2 -0
- data/Gemfile.lock +40 -35
- data/README.textile +11 -235
- data/Rakefile +1 -0
- data/doc/README.textile +363 -0
- data/{REVIEW_NOTES → doc/REVIEW_NOTES} +0 -0
- data/{RMU_REVIEW → doc/RMU_REVIEW} +0 -0
- data/{TODO.textile → doc/TODO.textile} +0 -0
- data/lib/themes_for_rails.rb +7 -6
- data/lib/themes_for_rails/{controller_methods.rb → action_controller.rb} +15 -9
- data/lib/themes_for_rails/action_mailer.rb +22 -0
- data/lib/themes_for_rails/action_view.rb +59 -0
- data/lib/themes_for_rails/assets_controller.rb +12 -13
- data/lib/themes_for_rails/common_methods.rb +28 -10
- data/lib/themes_for_rails/config.rb +44 -7
- data/lib/themes_for_rails/interpolation.rb +11 -0
- data/lib/themes_for_rails/railtie.rb +13 -2
- data/lib/themes_for_rails/routes.rb +15 -4
- data/lib/themes_for_rails/url_helpers.rb +16 -12
- data/lib/themes_for_rails/version.rb +2 -1
- data/test/lib/{controller_methods_test.rb → action_controller_test.rb} +59 -9
- data/test/lib/{mailer_methods_test.rb → action_mailer_test.rb} +2 -1
- data/test/lib/action_view_test.rb +54 -0
- data/test/lib/assets_controller_test.rb +11 -2
- data/test/lib/common_methods_test.rb +12 -6
- data/test/lib/config_test.rb +3 -2
- data/test/lib/integration_test.rb +12 -0
- data/test/lib/routes_test.rb +3 -2
- data/test/lib/themes_for_rails_test.rb +3 -2
- data/test/support/extensions.rb +1 -0
- data/test/test_helper.rb +1 -0
- data/themes_for_rails.gemspec +1 -0
- metadata +44 -28
- data/lib/themes_for_rails/mailer_methods.rb +0 -21
- data/lib/themes_for_rails/view_helpers.rb +0 -51
- data/test/lib/view_helpers_test.rb +0 -38
File without changes
|
File without changes
|
File without changes
|
data/lib/themes_for_rails.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
module ThemesForRails
|
2
|
-
|
3
|
-
VERSION = '0.4.3'
|
4
|
-
|
3
|
+
|
5
4
|
class << self
|
6
5
|
|
7
6
|
def config
|
@@ -45,13 +44,15 @@ module ThemesForRails
|
|
45
44
|
end
|
46
45
|
|
47
46
|
require 'active_support/dependencies'
|
47
|
+
require 'themes_for_rails/interpolation'
|
48
48
|
require 'themes_for_rails/config'
|
49
49
|
require 'themes_for_rails/common_methods'
|
50
50
|
require 'themes_for_rails/url_helpers'
|
51
|
-
|
51
|
+
|
52
|
+
require 'themes_for_rails/action_view'
|
52
53
|
require 'themes_for_rails/assets_controller'
|
53
|
-
require 'themes_for_rails/
|
54
|
-
require 'themes_for_rails/
|
54
|
+
require 'themes_for_rails/action_controller'
|
55
|
+
require 'themes_for_rails/action_mailer'
|
55
56
|
require 'themes_for_rails/railtie'
|
56
57
|
require 'themes_for_rails/routes'
|
57
58
|
|
@@ -1,26 +1,32 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
module ThemesForRails
|
2
|
-
|
3
|
+
|
4
|
+
module ActionController
|
5
|
+
|
3
6
|
extend ActiveSupport::Concern
|
7
|
+
|
4
8
|
included do
|
9
|
+
|
5
10
|
include ThemesForRails::CommonMethods
|
6
11
|
include ThemesForRails::UrlHelpers
|
12
|
+
|
7
13
|
end
|
14
|
+
|
8
15
|
module ClassMethods
|
16
|
+
|
9
17
|
def theme(name, options = {})
|
10
18
|
before_filter(options) do |controller|
|
11
19
|
controller.set_theme(name)
|
12
20
|
end
|
13
21
|
end
|
22
|
+
|
14
23
|
end
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
end
|
24
|
+
|
25
|
+
def theme(name)
|
26
|
+
set_theme(name)
|
19
27
|
end
|
20
|
-
end
|
21
|
-
end
|
22
28
|
|
23
|
-
|
29
|
+
end
|
24
30
|
|
25
|
-
|
31
|
+
end
|
26
32
|
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module ThemesForRails
|
3
|
+
|
4
|
+
module ActionMailer
|
5
|
+
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
include ThemesForRails::ActionController
|
10
|
+
alias_method_chain :mail, :theme
|
11
|
+
end
|
12
|
+
|
13
|
+
def mail_with_theme(headers = {}, &block)
|
14
|
+
theme_opts = headers[:theme] || self.class.default[:theme]
|
15
|
+
theme(theme_opts) if theme_opts
|
16
|
+
|
17
|
+
mail_without_theme(headers, &block)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module ThemesForRails
|
3
|
+
|
4
|
+
module ActionView
|
5
|
+
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
include ThemesForRails::CommonMethods
|
10
|
+
end
|
11
|
+
|
12
|
+
def current_theme_stylesheet_path(asset)
|
13
|
+
base_theme_stylesheet_path(:theme => self.theme_name, :asset => "#{asset}.css")
|
14
|
+
end
|
15
|
+
|
16
|
+
def current_theme_javascript_path(asset)
|
17
|
+
base_theme_javascript_path(:theme => self.theme_name, :asset => "#{asset}.js")
|
18
|
+
end
|
19
|
+
|
20
|
+
def current_theme_image_path(asset)
|
21
|
+
base_theme_image_path(:theme => self.theme_name, :asset => asset)
|
22
|
+
end
|
23
|
+
|
24
|
+
def theme_stylesheet_path(asset, new_theme_name = self.theme_name)
|
25
|
+
base_theme_stylesheet_path(:theme => new_theme_name, :asset => "#{asset}.css")
|
26
|
+
end
|
27
|
+
|
28
|
+
def theme_javascript_path(asset, new_theme_name = self.theme_name)
|
29
|
+
base_theme_javascript_path(:theme => new_theme_name, :asset => "#{asset}.js")
|
30
|
+
end
|
31
|
+
|
32
|
+
def theme_image_path(asset, new_theme_name = self.theme_name)
|
33
|
+
base_theme_image_path(:theme => new_theme_name, :asset => asset)
|
34
|
+
end
|
35
|
+
|
36
|
+
def theme_image_tag(source, options = {})
|
37
|
+
image_tag(theme_image_path(source), options)
|
38
|
+
end
|
39
|
+
|
40
|
+
def theme_image_submit_tag(source, options = {})
|
41
|
+
image_submit_tag(theme_image_path(source), options)
|
42
|
+
end
|
43
|
+
|
44
|
+
def theme_javascript_include_tag(*files)
|
45
|
+
options = files.extract_options!
|
46
|
+
options.merge!({ :type => "text/javascript" })
|
47
|
+
files.collect! {|file| theme_javascript_path(file) }
|
48
|
+
javascript_include_tag(*files, options)
|
49
|
+
end
|
50
|
+
|
51
|
+
def theme_stylesheet_link_tag(*files)
|
52
|
+
options = files.extract_options!
|
53
|
+
options.merge!({ :type => "text/css" })
|
54
|
+
files.collect! {|file| theme_stylesheet_path(file) }
|
55
|
+
stylesheet_link_tag(*files, options)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
@@ -1,49 +1,48 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
require "action_controller/metal"
|
2
3
|
|
3
4
|
module ThemesForRails
|
4
5
|
class AssetsController < ActionController::Base
|
5
6
|
|
6
|
-
include ThemesForRails::CommonMethods
|
7
|
-
include ThemesForRails::UrlHelpers
|
8
|
-
|
9
7
|
def stylesheets
|
10
|
-
handle_asset(
|
8
|
+
handle_asset("stylesheets")
|
11
9
|
end
|
12
10
|
|
13
11
|
def javascripts
|
14
|
-
handle_asset(
|
12
|
+
handle_asset("javascripts")
|
15
13
|
end
|
16
14
|
|
17
15
|
def images
|
18
|
-
handle_asset(
|
16
|
+
handle_asset("images")
|
19
17
|
end
|
20
18
|
|
21
19
|
private
|
22
20
|
|
23
|
-
def handle_asset(
|
21
|
+
def handle_asset(prefix)
|
22
|
+
asset, theme = params[:asset], params[:theme]
|
24
23
|
find_themed_asset(asset, theme, prefix) do |path, mime_type|
|
25
24
|
send_file path, :type => mime_type, :disposition => "inline"
|
26
25
|
end
|
27
26
|
end
|
28
27
|
|
29
|
-
def find_themed_asset(asset_name, asset_theme,
|
30
|
-
path = asset_path(asset_name, asset_theme,
|
28
|
+
def find_themed_asset(asset_name, asset_theme, asset_type, &block)
|
29
|
+
path = asset_path(asset_name, asset_theme, asset_type)
|
31
30
|
if File.exists?(path)
|
32
31
|
yield path, mime_type_for(request)
|
33
32
|
elsif File.extname(path).blank?
|
34
33
|
asset_name = "#{asset_name}.#{extension_from(request.path_info)}"
|
35
|
-
return find_themed_asset(asset_name, asset_theme,
|
34
|
+
return find_themed_asset(asset_name, asset_theme, asset_type, &block)
|
36
35
|
else
|
37
36
|
render_not_found
|
38
37
|
end
|
39
38
|
end
|
40
39
|
|
41
|
-
def asset_path(asset_name, asset_theme,
|
42
|
-
File.join(
|
40
|
+
def asset_path(asset_name, asset_theme, asset_type)
|
41
|
+
File.join(theme_asset_path_for(asset_theme), asset_type, asset_name)
|
43
42
|
end
|
44
43
|
|
45
44
|
def render_not_found
|
46
|
-
render :text => '
|
45
|
+
render :text => 'Not found', :status => 404
|
47
46
|
end
|
48
47
|
|
49
48
|
def mime_type_for(request)
|
@@ -1,8 +1,9 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
module ThemesForRails
|
2
3
|
module CommonMethods
|
3
|
-
|
4
|
-
|
5
|
-
|
4
|
+
|
5
|
+
include ThemesForRails::Interpolation
|
6
|
+
|
6
7
|
def theme_name
|
7
8
|
@cached_theme_name ||= begin
|
8
9
|
case @theme_name
|
@@ -14,35 +15,52 @@ module ThemesForRails
|
|
14
15
|
end
|
15
16
|
end
|
16
17
|
end
|
18
|
+
|
17
19
|
def theme_name=(name)
|
18
20
|
@theme_name = name
|
19
21
|
end
|
22
|
+
|
20
23
|
def set_theme(name)
|
21
24
|
self.theme_name = name
|
22
25
|
if valid_theme?
|
23
26
|
add_theme_view_path
|
24
27
|
end
|
25
28
|
end
|
26
|
-
|
29
|
+
|
30
|
+
public
|
31
|
+
|
27
32
|
def valid_theme?
|
28
33
|
!self.theme_name.nil?
|
29
34
|
end
|
35
|
+
|
30
36
|
# will add the view path for the current theme
|
31
37
|
def add_theme_view_path
|
32
38
|
add_theme_view_path_for(self.theme_name)
|
33
39
|
end
|
40
|
+
|
34
41
|
# will add the view path for a given theme name
|
35
42
|
def add_theme_view_path_for(name)
|
36
|
-
self.view_paths.insert 0, ActionView::FileSystemResolver.new(
|
43
|
+
self.view_paths.insert 0, ::ActionView::FileSystemResolver.new(theme_view_path_for(name))
|
37
44
|
end
|
45
|
+
|
38
46
|
def public_theme_path
|
39
|
-
|
47
|
+
theme_view_path("/")
|
48
|
+
end
|
49
|
+
|
50
|
+
def theme_asset_path
|
51
|
+
theme_asset_path_for(theme_name)
|
52
|
+
end
|
53
|
+
|
54
|
+
def theme_view_path
|
55
|
+
theme_view_path_for(theme_name)
|
40
56
|
end
|
41
|
-
|
42
|
-
|
57
|
+
|
58
|
+
def theme_view_path_for(theme_name)
|
59
|
+
interpolate(ThemesForRails.config.views_dir, theme_name)
|
43
60
|
end
|
44
|
-
|
45
|
-
|
61
|
+
|
62
|
+
def theme_asset_path_for(theme_name)
|
63
|
+
interpolate(ThemesForRails.config.assets_dir, theme_name)
|
46
64
|
end
|
47
65
|
end
|
48
66
|
end
|
@@ -1,29 +1,66 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
module ThemesForRails
|
2
3
|
class Config
|
3
4
|
|
4
|
-
attr_writer :base_dir, :themes_dir
|
5
|
-
attr_accessor :use_sass
|
5
|
+
attr_writer :base_dir, :themes_dir, :assets_dir, :views_dir, :themes_routes_dir
|
6
|
+
attr_accessor :use_sass, :default_theme
|
6
7
|
|
8
|
+
include Interpolation
|
9
|
+
|
7
10
|
def initialize(&block)
|
8
11
|
@use_sass = true
|
12
|
+
@default_theme = 'default'
|
9
13
|
yield if block_given?
|
10
14
|
end
|
11
15
|
|
12
16
|
def base_dir
|
13
|
-
@base_dir ||= Rails.root
|
17
|
+
@base_dir ||= Rails.root.to_s
|
18
|
+
end
|
19
|
+
|
20
|
+
# relative assets dir for view overloading support
|
21
|
+
# used for theme_view_path_for method to get theme path and add to view paths.
|
22
|
+
# Defaults to themes_dir for non asset pipeline users
|
23
|
+
#
|
24
|
+
# If you are using the Rails Asset Pipeline, this should be changed to the
|
25
|
+
# path of your assets in your app. For example, if you store your themes
|
26
|
+
# under /app/assets/themes - {Rails.root}/app/assets/themes
|
27
|
+
# you would need to set this to 'app/assets/themes' in your initializer config
|
28
|
+
def assets_dir
|
29
|
+
@assets_dir ||= ":root/themes/:name"
|
30
|
+
end
|
31
|
+
|
32
|
+
# relative views directory for theme views to be separated from assets
|
33
|
+
# used for Asset Pipeline support. Defaults to match {assets_dir}/views
|
34
|
+
def views_dir
|
35
|
+
@views_dir ||= ":root/themes/:name/views"
|
14
36
|
end
|
15
37
|
|
16
38
|
def themes_dir
|
17
|
-
@themes_dir ||= "themes"
|
39
|
+
@themes_dir ||= ":root/themes"
|
18
40
|
end
|
19
41
|
|
42
|
+
# Full path to themes
|
20
43
|
def themes_path
|
21
|
-
|
44
|
+
interpolate(themes_dir)
|
22
45
|
end
|
23
|
-
|
46
|
+
|
47
|
+
# This is the base themes dir that is used for mapping URL paths.
|
48
|
+
#
|
49
|
+
# If you are using the Rails Asset Pipeline, this should be changed to the
|
50
|
+
# prefix dir of your assets path. For example, if you store your themes
|
51
|
+
# under /app/assets/themes - {Rails.root}/app/assets/themes
|
52
|
+
# you would need to set this value to 'assets' to match up with the Sprockets
|
53
|
+
# path resolution process.
|
54
|
+
|
55
|
+
def themes_routes_dir
|
56
|
+
@themes_routes_dir ||= "themes"
|
57
|
+
end
|
58
|
+
|
24
59
|
def clear
|
25
|
-
@base_dir
|
60
|
+
@base_dir = nil
|
26
61
|
@themes_dir = nil
|
62
|
+
@assets_dir = nil
|
63
|
+
@views_dir = nil
|
27
64
|
end
|
28
65
|
|
29
66
|
def use_sass?
|
@@ -1,7 +1,7 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# encoding: utf-8
|
3
2
|
module ThemesForRails
|
4
3
|
class Railtie < ::Rails::Railtie
|
4
|
+
|
5
5
|
config.themes_for_rails = ActiveSupport::OrderedOptions.new
|
6
6
|
|
7
7
|
config.to_prepare do
|
@@ -12,6 +12,17 @@ module ThemesForRails
|
|
12
12
|
# Adding theme stylesheets path to sass, automatically.
|
13
13
|
ThemesForRails.add_themes_path_to_sass if ThemesForRails.config.use_sass?
|
14
14
|
|
15
|
+
ActiveSupport.on_load(:action_view) do
|
16
|
+
include ThemesForRails::ActionView
|
17
|
+
end
|
18
|
+
|
19
|
+
ActiveSupport.on_load(:action_controller) do
|
20
|
+
include ThemesForRails::ActionController
|
21
|
+
end
|
22
|
+
|
23
|
+
ActiveSupport.on_load(:action_mailer) do
|
24
|
+
include ThemesForRails::ActionMailer
|
25
|
+
end
|
15
26
|
end
|
16
27
|
|
17
28
|
rake_tasks do
|
@@ -1,16 +1,27 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
module ThemesForRails
|
2
3
|
module Routes
|
4
|
+
|
3
5
|
def themes_for_rails
|
4
|
-
theme_dir = ThemesForRails.config.
|
5
|
-
|
6
|
-
|
7
|
-
match "#{theme_dir}/:theme/
|
6
|
+
theme_dir = ThemesForRails.config.themes_routes_dir
|
7
|
+
constraints = { :theme => /[\w\.]*/ }
|
8
|
+
|
9
|
+
match "#{theme_dir}/:theme/stylesheets/*asset" => 'themes_for_rails/assets#stylesheets',
|
10
|
+
:as => :base_theme_stylesheet, :constraints => constraints
|
11
|
+
match "#{theme_dir}/:theme/javascripts/*asset" => 'themes_for_rails/assets#javascripts',
|
12
|
+
:as => :base_theme_javascript, :constraints => constraints
|
13
|
+
match "#{theme_dir}/:theme/images/*asset" => 'themes_for_rails/assets#images',
|
14
|
+
:as => :base_theme_image, :constraints => constraints
|
8
15
|
end
|
16
|
+
|
9
17
|
end
|
10
18
|
end
|
19
|
+
|
11
20
|
module ActionDispatch::Routing
|
12
21
|
class Mapper #:nodoc:
|
22
|
+
|
13
23
|
include ThemesForRails::Routes
|
24
|
+
|
14
25
|
end
|
15
26
|
end
|
16
27
|
|
@@ -1,23 +1,27 @@
|
|
1
|
+
# encoding: utf-8
|
1
2
|
module ThemesForRails
|
2
3
|
module UrlHelpers
|
4
|
+
|
3
5
|
extend ActiveSupport::Concern
|
6
|
+
|
4
7
|
included do
|
5
|
-
include ThemesForRails::CommonMethods
|
6
8
|
helper_method :current_theme_stylesheet_path,
|
7
9
|
:current_theme_javascript_path,
|
8
10
|
:current_theme_image_path
|
9
11
|
end
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
end
|
14
|
-
def current_theme_javascript_path(asset)
|
15
|
-
base_theme_javascript_path(:theme => self.theme_name, :asset => "#{asset}.js")
|
16
|
-
end
|
17
|
-
def current_theme_image_path(asset)
|
18
|
-
image, extension = asset.split(".")
|
19
|
-
base_theme_image_path(:theme => self.theme_name, :asset => "#{image}.#{extension}")
|
20
|
-
end
|
12
|
+
|
13
|
+
def current_theme_stylesheet_path(asset)
|
14
|
+
base_theme_stylesheet_path(:theme => self.theme_name, :asset => "#{asset}.css")
|
21
15
|
end
|
16
|
+
|
17
|
+
def current_theme_javascript_path(asset)
|
18
|
+
base_theme_javascript_path(:theme => self.theme_name, :asset => "#{asset}.js")
|
19
|
+
end
|
20
|
+
|
21
|
+
def current_theme_image_path(asset)
|
22
|
+
image, extension = asset.split(".")
|
23
|
+
base_theme_image_path(:theme => self.theme_name, :asset => "#{image}.#{extension}")
|
24
|
+
end
|
25
|
+
|
22
26
|
end
|
23
27
|
end
|