themes_for_rails 0.4.0 → 0.4.1
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/Gemfile.lock +1 -1
- data/README.textile +4 -1
- data/lib/generators/themes_for_rails/install_generator.rb +5 -0
- data/lib/themes_for_rails.rb +3 -7
- data/lib/themes_for_rails/common_methods.rb +7 -7
- data/lib/themes_for_rails/version.rb +1 -1
- data/lib/themes_for_rails/view_helpers.rb +7 -7
- data/test/common_methods_test.rb +22 -0
- data/test/controller_methods_test.rb +26 -4
- data/test/themes_for_rails_test.rb +7 -1
- data/test/view_helpers_test.rb +10 -7
- data/themes_for_rails.gemspec +4 -2
- metadata +5 -3
data/Gemfile.lock
CHANGED
data/README.textile
CHANGED
@@ -117,7 +117,7 @@ theme_stylesheet_path
|
|
117
117
|
|
118
118
|
h2. Generators
|
119
119
|
|
120
|
-
For now, it only creates the theme folder.
|
120
|
+
For now, it only creates the theme folder and add the "themes_for_rails" route in the routes.rb.
|
121
121
|
|
122
122
|
<pre>
|
123
123
|
rails generate themes_for_rails:install
|
@@ -235,6 +235,9 @@ rake
|
|
235
235
|
h2. Authors and contributors
|
236
236
|
|
237
237
|
* lucasefe
|
238
|
+
* jbarreneche
|
239
|
+
* kule
|
240
|
+
* matheusmoreira
|
238
241
|
|
239
242
|
h2. Last but not least
|
240
243
|
|
data/lib/themes_for_rails.rb
CHANGED
@@ -7,9 +7,10 @@ module ThemesForRails
|
|
7
7
|
@config
|
8
8
|
end
|
9
9
|
|
10
|
-
def available_themes
|
11
|
-
Dir.glob(File.join(config.base_dir, config.themes_dir, "*"))
|
10
|
+
def available_themes(&block)
|
11
|
+
Dir.glob(File.join(config.base_dir, config.themes_dir, "*"), &block)
|
12
12
|
end
|
13
|
+
alias each_theme_dir available_themes
|
13
14
|
|
14
15
|
def available_theme_names
|
15
16
|
available_themes.map {|theme| File.basename(theme) }
|
@@ -37,11 +38,6 @@ module ThemesForRails
|
|
37
38
|
Sass::Plugin.template_location_array.map(&:first).include?(sass_dir)
|
38
39
|
end
|
39
40
|
|
40
|
-
def each_theme_dir
|
41
|
-
Dir.glob(File.join(Rails.root, config.themes_dir, "*")) do |theme_dir|
|
42
|
-
yield(theme_dir) if block_given?
|
43
|
-
end
|
44
|
-
end
|
45
41
|
end
|
46
42
|
end
|
47
43
|
|
@@ -7,7 +7,7 @@ module ThemesForRails
|
|
7
7
|
@cached_theme_name ||= begin
|
8
8
|
case @theme_name
|
9
9
|
when Symbol then
|
10
|
-
self.respond_to?(@theme_name) ? self.send(@theme_name) : @theme_name.to_s
|
10
|
+
self.respond_to?(@theme_name, true) ? self.send(@theme_name) : @theme_name.to_s
|
11
11
|
when String then @theme_name
|
12
12
|
else
|
13
13
|
nil
|
@@ -18,10 +18,10 @@ module ThemesForRails
|
|
18
18
|
@theme_name = name
|
19
19
|
end
|
20
20
|
def set_theme(name)
|
21
|
-
self.theme_name = name
|
21
|
+
self.theme_name = name
|
22
22
|
if valid_theme?
|
23
|
-
add_theme_view_path
|
24
|
-
end
|
23
|
+
add_theme_view_path
|
24
|
+
end
|
25
25
|
end
|
26
26
|
public
|
27
27
|
def valid_theme?
|
@@ -38,11 +38,11 @@ module ThemesForRails
|
|
38
38
|
def public_theme_path
|
39
39
|
theme_path("/")
|
40
40
|
end
|
41
|
-
def theme_path(base =
|
41
|
+
def theme_path(base = ThemesForRails.config.base_dir)
|
42
42
|
theme_path_for(theme_name, base)
|
43
43
|
end
|
44
|
-
def theme_path_for(name, base =
|
45
|
-
File.join(base,
|
44
|
+
def theme_path_for(name, base = ThemesForRails.config.base_dir, theme_dir = ThemesForRails.config.themes_dir)
|
45
|
+
File.join(base, theme_dir, name)
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module ThemesForRails
|
2
2
|
module ViewHelpers
|
3
|
-
|
3
|
+
|
4
4
|
extend ActiveSupport::Concern
|
5
|
-
|
5
|
+
|
6
6
|
included do
|
7
7
|
include ThemesForRails::CommonMethods
|
8
8
|
end
|
@@ -16,20 +16,20 @@ module ThemesForRails
|
|
16
16
|
def current_theme_image_path(asset)
|
17
17
|
base_theme_image_path(:theme => self.theme_name, :asset => asset)
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
alias_method :theme_image_path, :current_theme_image_path
|
21
21
|
alias_method :theme_javascript_path, :current_theme_javascript_path
|
22
22
|
alias_method :theme_stylesheet_path, :current_theme_stylesheet_path
|
23
23
|
|
24
|
-
def theme_image_tag(source)
|
25
|
-
image_tag(theme_image_path(source))
|
24
|
+
def theme_image_tag(source, options = {})
|
25
|
+
image_tag(theme_image_path(source), options)
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
def theme_javascript_include_tag(*files)
|
29
29
|
files.collect! {|file| theme_javascript_path(file) }
|
30
30
|
javascript_include_tag *files
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
def theme_stylesheet_link_tag(*files)
|
34
34
|
options = files.extract_options!
|
35
35
|
files.collect! {|file| theme_stylesheet_path(file) }
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require File.expand_path("test/test_helper.rb")
|
2
|
+
|
3
|
+
class ThemesForRailsTest < Test::Unit::TestCase
|
4
|
+
setup do
|
5
|
+
@common = Object.new
|
6
|
+
@common.extend ThemesForRails::CommonMethods
|
7
|
+
@common.theme_name = "awesome"
|
8
|
+
ThemesForRails.config.clear
|
9
|
+
end
|
10
|
+
should 'use config base_dir to build theme path' do
|
11
|
+
ThemesForRails.config.base_dir ='some_path'
|
12
|
+
assert_match /some_path/, @common.theme_path
|
13
|
+
end
|
14
|
+
should 'use config themes_dir to build theme path' do
|
15
|
+
ThemesForRails.config.themes_dir ='skinner'
|
16
|
+
assert_match /skinner/, @common.theme_path
|
17
|
+
end
|
18
|
+
should 'use config base_dir to build theme path for theme' do
|
19
|
+
ThemesForRails.config.base_dir ='some_path'
|
20
|
+
assert_match /some_path/, @common.theme_path_for('doodley')
|
21
|
+
end
|
22
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require "test_helper"
|
1
|
+
require File.expand_path("test/test_helper.rb")
|
2
2
|
|
3
3
|
class MyController < ActionController::Base
|
4
4
|
def hello
|
@@ -9,6 +9,21 @@ class CustomThemeController < ActionController::Base
|
|
9
9
|
def hello
|
10
10
|
render :text => "Just a test"
|
11
11
|
end
|
12
|
+
|
13
|
+
def theme_selector
|
14
|
+
'custom'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
class PrivateCustomThemeController < ActionController::Base
|
18
|
+
def hello
|
19
|
+
render :text => "Just a test"
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def private_theme_selector
|
25
|
+
'private_custom'
|
26
|
+
end
|
12
27
|
end
|
13
28
|
|
14
29
|
class ActionMailerInclusionTest < Test::Unit::TestCase
|
@@ -46,11 +61,18 @@ module ThemesForRails
|
|
46
61
|
end
|
47
62
|
context "setting the theme with a Symbol" do
|
48
63
|
tests CustomThemeController
|
49
|
-
should "call the selected method" do
|
50
|
-
@controller.expects(:theme_selector).returns('custom')
|
64
|
+
should "call the selected private method" do
|
51
65
|
CustomThemeController.theme :theme_selector
|
52
|
-
assert_equal nil, @controller.theme_name
|
53
66
|
get :hello
|
67
|
+
assert_equal 'custom', @controller.theme_name
|
68
|
+
end
|
69
|
+
end
|
70
|
+
context "setting the theme with a Symbol (private)" do
|
71
|
+
tests PrivateCustomThemeController
|
72
|
+
should "call the selected private method" do
|
73
|
+
PrivateCustomThemeController.theme :private_theme_selector
|
74
|
+
get :hello
|
75
|
+
assert_equal 'private_custom', @controller.theme_name
|
54
76
|
end
|
55
77
|
end
|
56
78
|
end
|
@@ -4,5 +4,11 @@ class ThemesForRailsTest < Test::Unit::TestCase
|
|
4
4
|
should 'know the available themes' do
|
5
5
|
assert_equal ['default'], ThemesForRails.available_theme_names
|
6
6
|
end
|
7
|
-
|
7
|
+
should 'use config for each_theme_dir' do
|
8
|
+
ThemesForRails.config.base_dir = Rails.root + 'app'
|
9
|
+
assert_equal ['app_theme'], ThemesForRails.each_theme_dir.map {|f| File.basename(f) }
|
10
|
+
end
|
11
|
+
teardown do
|
12
|
+
ThemesForRails.config.clear
|
13
|
+
end
|
8
14
|
end
|
data/test/view_helpers_test.rb
CHANGED
@@ -3,25 +3,28 @@ require "test_helper"
|
|
3
3
|
module ThemesForRails
|
4
4
|
class ViewHelpersTest < ActionController::IntegrationTest
|
5
5
|
include ThemesForRails::ViewHelpers
|
6
|
-
|
6
|
+
|
7
7
|
include ActionView::Helpers::AssetTagHelper
|
8
8
|
include ERB::Util
|
9
9
|
include ActionView::Helpers::TagHelper
|
10
|
-
|
10
|
+
|
11
11
|
def theme_name
|
12
12
|
'default'
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
def config
|
16
16
|
@config ||= stub({:perform_caching => false, :asset_path => "/assets", :asset_host => ''})
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
should 'delegate to stylesheet_link_tag' do
|
20
|
-
|
20
|
+
assert_match /media=.screen/, theme_stylesheet_link_tag('cuac.css')
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
should 'delegate options (lazy testing, I know)' do
|
24
|
-
|
24
|
+
assert_match /media=.print/, theme_stylesheet_link_tag('cuac.css', :media => 'print')
|
25
|
+
end
|
26
|
+
should 'delegate options in image_tag' do
|
27
|
+
assert_match /width=.40/, theme_image_tag('image.css', :size => '40x50')
|
25
28
|
end
|
26
29
|
end
|
27
30
|
end
|
data/themes_for_rails.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{themes_for_rails}
|
8
|
-
s.version = "0.4.
|
8
|
+
s.version = "0.4.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Lucas Florio"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-02-02}
|
13
13
|
s.description = %q{It allows an application to have many different ways of rendering static assets and dynamic views. }
|
14
14
|
s.email = %q{lucasefe@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -44,6 +44,7 @@ Gem::Specification.new do |s|
|
|
44
44
|
"lib/themes_for_rails/version.rb",
|
45
45
|
"lib/themes_for_rails/view_helpers.rb",
|
46
46
|
"test/assets_controller_test.rb",
|
47
|
+
"test/common_methods_test.rb",
|
47
48
|
"test/config_test.rb",
|
48
49
|
"test/controller_methods_test.rb",
|
49
50
|
"test/dummy_app/.gitignore",
|
@@ -114,6 +115,7 @@ Gem::Specification.new do |s|
|
|
114
115
|
s.summary = %q{Themes support for rails (3)}
|
115
116
|
s.test_files = [
|
116
117
|
"test/assets_controller_test.rb",
|
118
|
+
"test/common_methods_test.rb",
|
117
119
|
"test/config_test.rb",
|
118
120
|
"test/controller_methods_test.rb",
|
119
121
|
"test/dummy_app/app/controllers/application_controller.rb",
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 4
|
8
|
-
-
|
9
|
-
version: 0.4.
|
8
|
+
- 1
|
9
|
+
version: 0.4.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Lucas Florio
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-
|
17
|
+
date: 2011-02-02 00:00:00 -03:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -55,6 +55,7 @@ files:
|
|
55
55
|
- lib/themes_for_rails/version.rb
|
56
56
|
- lib/themes_for_rails/view_helpers.rb
|
57
57
|
- test/assets_controller_test.rb
|
58
|
+
- test/common_methods_test.rb
|
58
59
|
- test/config_test.rb
|
59
60
|
- test/controller_methods_test.rb
|
60
61
|
- test/dummy_app/.gitignore
|
@@ -151,6 +152,7 @@ specification_version: 3
|
|
151
152
|
summary: Themes support for rails (3)
|
152
153
|
test_files:
|
153
154
|
- test/assets_controller_test.rb
|
155
|
+
- test/common_methods_test.rb
|
154
156
|
- test/config_test.rb
|
155
157
|
- test/controller_methods_test.rb
|
156
158
|
- test/dummy_app/app/controllers/application_controller.rb
|