themes_for_rails 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/README.textile +24 -2
- data/lib/generators/{theme_for_rails → themes_for_rails}/install_generator.rb +1 -1
- data/lib/generators/{theme_for_rails → themes_for_rails}/templates/theme/images/.gitkeep +0 -0
- data/lib/generators/{theme_for_rails → themes_for_rails}/templates/theme/javascripts/.gitkeep +0 -0
- data/lib/generators/{theme_for_rails → themes_for_rails}/templates/theme/stylesheets/.gitkeep +0 -0
- data/lib/generators/{theme_for_rails → themes_for_rails}/templates/theme/views/layouts/.gitkeep +0 -0
- data/lib/generators/{theme_for_rails → themes_for_rails}/theme_generator.rb +1 -1
- data/lib/themes_for_rails/assets_controller.rb +18 -17
- data/lib/themes_for_rails/config.rb +9 -0
- data/lib/themes_for_rails/railtie.rb +5 -0
- data/lib/themes_for_rails/version.rb +1 -1
- data/lib/themes_for_rails/view_helpers.rb +9 -2
- data/lib/themes_for_rails.rb +27 -0
- data/test/assets_controller_test.rb +7 -1
- data/test/dummy_app/themes/default/stylesheets/images/logo.png +0 -0
- data/test/support/extensions.rb +3 -0
- data/test/view_helpers_test.rb +27 -0
- data/themes_for_rails.gemspec +12 -9
- metadata +13 -10
data/Gemfile.lock
CHANGED
data/README.textile
CHANGED
@@ -120,13 +120,13 @@ h2. Generators
|
|
120
120
|
For now, it only creates the theme folder.
|
121
121
|
|
122
122
|
<pre>
|
123
|
-
rails generate
|
123
|
+
rails generate themes_for_rails:install
|
124
124
|
</pre>
|
125
125
|
|
126
126
|
Inside the themes folder, it create a structure for my_theme.
|
127
127
|
|
128
128
|
<pre>
|
129
|
-
rails generate
|
129
|
+
rails generate themes_for_rails:theme my_theme
|
130
130
|
</pre>
|
131
131
|
|
132
132
|
h2. Changing things
|
@@ -155,6 +155,22 @@ KillerApp::Application.configure do
|
|
155
155
|
end
|
156
156
|
</pre>
|
157
157
|
|
158
|
+
h2. Sass support
|
159
|
+
|
160
|
+
ThemesForRails will automatically add the themes paths to Sass, if sass is available.
|
161
|
+
|
162
|
+
For instance, everything you put inside themes/my_theme/stylesheets/sass will get compiled into themes/my_theme/stylesheets (duh, right?)
|
163
|
+
|
164
|
+
To bypass sass configuration, do this:
|
165
|
+
<pre>
|
166
|
+
KillerApp::Application.configure do
|
167
|
+
#
|
168
|
+
|
169
|
+
config.themes_for_rails.use_sass = false
|
170
|
+
|
171
|
+
#...
|
172
|
+
end
|
173
|
+
</pre>
|
158
174
|
|
159
175
|
h2. Another way to change things
|
160
176
|
|
@@ -219,3 +235,9 @@ rake
|
|
219
235
|
h2. Authors and contributors
|
220
236
|
|
221
237
|
* lucasefe
|
238
|
+
|
239
|
+
h2. Last but not least
|
240
|
+
|
241
|
+
If you are using this gem, please, take a minute to recommend me at Working With Rails.
|
242
|
+
|
243
|
+
<a href="http://www.workingwithrails.com/recommendation/new/person/7277-lucas-florio"><img alt="Recommend Me" src="http://workingwithrails.com/images/tools/compact-small.jpg" /></a>
|
File without changes
|
data/lib/generators/{theme_for_rails → themes_for_rails}/templates/theme/javascripts/.gitkeep
RENAMED
File without changes
|
data/lib/generators/{theme_for_rails → themes_for_rails}/templates/theme/stylesheets/.gitkeep
RENAMED
File without changes
|
data/lib/generators/{theme_for_rails → themes_for_rails}/templates/theme/views/layouts/.gitkeep
RENAMED
File without changes
|
@@ -7,26 +7,27 @@ module ThemesForRails
|
|
7
7
|
include ThemesForRails::UrlHelpers
|
8
8
|
|
9
9
|
def stylesheets
|
10
|
-
|
11
|
-
render_asset theme_stylesheet_path_for(params[:theme], filename), 'text/css'
|
10
|
+
render_asset asset_path_for(params[:asset], 'stylesheets'), mime_type_from(params[:asset])
|
12
11
|
end
|
13
12
|
|
14
13
|
def javascripts
|
15
|
-
|
16
|
-
render_asset theme_javascript_path_for(params[:theme], filename), 'text/javascript'
|
14
|
+
render_asset asset_path_for(params[:asset], 'javascripts'), mime_type_from(params[:asset])
|
17
15
|
end
|
18
16
|
|
19
17
|
def images
|
20
|
-
|
21
|
-
render_asset theme_image_path_for(params[:theme], filename, extension), "image/#{extension.gsub('.', '')}"
|
18
|
+
render_asset asset_path_for(params[:asset], 'images'), mime_type_from(params[:asset])
|
22
19
|
end
|
23
20
|
|
24
21
|
private
|
25
22
|
|
23
|
+
def asset_path_for(asset_url, asset_prefix)
|
24
|
+
File.join(theme_path_for(params[:theme]), asset_prefix, params[:asset])
|
25
|
+
end
|
26
|
+
|
26
27
|
def extract_filename_and_extension_from(asset)
|
27
28
|
extension = File.extname(asset)
|
28
29
|
filename = params[:asset].gsub(extension, '')
|
29
|
-
return filename, extension
|
30
|
+
return filename, extension[1..-1]
|
30
31
|
end
|
31
32
|
|
32
33
|
def render_asset(asset, mime_type)
|
@@ -36,16 +37,16 @@ module ThemesForRails
|
|
36
37
|
send_file asset, :type => mime_type
|
37
38
|
end
|
38
39
|
end
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
40
|
+
|
41
|
+
def mime_type_from(asset_path)
|
42
|
+
extension = extract_filename_and_extension_from(asset_path).last
|
43
|
+
if extension == 'css'
|
44
|
+
"text/css"
|
45
|
+
elsif extension == 'js'
|
46
|
+
'text/javascript'
|
47
|
+
else
|
48
|
+
"image/#{extension}"
|
49
|
+
end
|
49
50
|
end
|
50
51
|
end
|
51
52
|
end
|
@@ -2,8 +2,10 @@ module ThemesForRails
|
|
2
2
|
class Config
|
3
3
|
|
4
4
|
attr_writer :base_dir, :themes_dir
|
5
|
+
attr_accessor :use_sass
|
5
6
|
|
6
7
|
def initialize(&block)
|
8
|
+
@use_sass = true
|
7
9
|
yield if block_given?
|
8
10
|
end
|
9
11
|
|
@@ -20,5 +22,12 @@ module ThemesForRails
|
|
20
22
|
@themes_dir = nil
|
21
23
|
end
|
22
24
|
|
25
|
+
def use_sass?
|
26
|
+
@use_sass and sass_is_available?
|
27
|
+
end
|
28
|
+
|
29
|
+
def sass_is_available?
|
30
|
+
!!defined?Sass::Plugin
|
31
|
+
end
|
23
32
|
end
|
24
33
|
end
|
@@ -8,7 +8,12 @@ module ThemesForRails
|
|
8
8
|
ThemesForRails::Railtie.config.themes_for_rails.each do |key, value|
|
9
9
|
ThemesForRails.config.send "#{key}=".to_sym, value
|
10
10
|
end
|
11
|
+
|
12
|
+
# Adding theme stylesheets path to sass, automatically.
|
13
|
+
ThemesForRails.add_themes_path_to_sass if ThemesForRails.config.use_sass?
|
14
|
+
|
11
15
|
end
|
16
|
+
|
12
17
|
rake_tasks do
|
13
18
|
load "tasks/themes_for_rails.rake"
|
14
19
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module ThemesForRails
|
2
2
|
module ViewHelpers
|
3
|
+
|
3
4
|
extend ActiveSupport::Concern
|
5
|
+
|
4
6
|
included do
|
5
7
|
include ThemesForRails::CommonMethods
|
6
8
|
end
|
@@ -12,8 +14,9 @@ module ThemesForRails
|
|
12
14
|
base_theme_javascript_path(:theme => self.theme_name, :asset => "#{asset}.js")
|
13
15
|
end
|
14
16
|
def current_theme_image_path(asset)
|
15
|
-
|
17
|
+
base_theme_image_path(:theme => self.theme_name, :asset => asset)
|
16
18
|
end
|
19
|
+
|
17
20
|
alias_method :theme_image_path, :current_theme_image_path
|
18
21
|
alias_method :theme_javascript_path, :current_theme_javascript_path
|
19
22
|
alias_method :theme_stylesheet_path, :current_theme_stylesheet_path
|
@@ -21,13 +24,17 @@ module ThemesForRails
|
|
21
24
|
def theme_image_tag(source)
|
22
25
|
image_tag(theme_image_path(source))
|
23
26
|
end
|
27
|
+
|
24
28
|
def theme_javascript_include_tag(*files)
|
25
29
|
files.collect! {|file| theme_javascript_path(file) }
|
26
30
|
javascript_include_tag *files
|
27
31
|
end
|
32
|
+
|
28
33
|
def theme_stylesheet_link_tag(*files)
|
34
|
+
options = files.extract_options!
|
29
35
|
files.collect! {|file| theme_stylesheet_path(file) }
|
30
|
-
|
36
|
+
files << options
|
37
|
+
stylesheet_link_tag(*files)
|
31
38
|
end
|
32
39
|
end
|
33
40
|
end
|
data/lib/themes_for_rails.rb
CHANGED
@@ -14,7 +14,34 @@ module ThemesForRails
|
|
14
14
|
def available_theme_names
|
15
15
|
available_themes.map {|theme| File.basename(theme) }
|
16
16
|
end
|
17
|
+
|
18
|
+
def add_themes_path_to_sass
|
19
|
+
if ThemesForRails.config.sass_is_available?
|
20
|
+
each_theme_dir do |dir|
|
21
|
+
if File.directory?(dir) # Need to get rid of the '.' and '..'
|
22
|
+
|
23
|
+
sass_dir = "#{dir}/stylesheets/sass"
|
24
|
+
css_dir = "#{dir}/stylesheets"
|
17
25
|
|
26
|
+
unless already_configured_in_sass?(sass_dir)
|
27
|
+
Sass::Plugin.add_template_location sass_dir, css_dir
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
else
|
32
|
+
raise "Sass is not available. What are you trying to do?"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def already_configured_in_sass?(sass_dir)
|
37
|
+
Sass::Plugin.template_location_array.map(&:first).include?(sass_dir)
|
38
|
+
end
|
39
|
+
|
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
|
18
45
|
end
|
19
46
|
end
|
20
47
|
|
@@ -37,7 +37,7 @@ module ThemesForRails
|
|
37
37
|
should "respond with the right image file when requested" do
|
38
38
|
get 'images', { :theme => 'default', :asset => 'logo.png'}
|
39
39
|
assert_response :success
|
40
|
-
assert_equal @response.content_type
|
40
|
+
assert_equal 'image/png', @response.content_type
|
41
41
|
end
|
42
42
|
should "not be success when the image file is not found" do
|
43
43
|
get 'images', { :theme => 'default', :asset => 'i_am_not_here.jpg'}
|
@@ -47,6 +47,12 @@ module ThemesForRails
|
|
47
47
|
should "respond with a nested asset" do
|
48
48
|
get 'images', { :theme => 'default', :asset => 'nested/logo.png'}
|
49
49
|
assert_response :success
|
50
|
+
assert_equal 'image/png', @response.content_type
|
51
|
+
end
|
52
|
+
|
53
|
+
should "respond with properly even when requesting an image inside the stylesheets folder" do
|
54
|
+
get 'stylesheets', { :theme => 'default', :asset => 'images/logo.png'}
|
55
|
+
assert_response :success
|
50
56
|
assert_equal @response.content_type, 'image/png'
|
51
57
|
end
|
52
58
|
end
|
File without changes
|
data/test/support/extensions.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
require 'active_support/test_case'
|
2
2
|
|
3
3
|
class ActiveSupport::TestCase
|
4
|
+
|
4
5
|
def assert_named_route(result, name)
|
5
6
|
assert_equal result, @routes.url_helpers.send(name)
|
6
7
|
end
|
8
|
+
|
7
9
|
def assert_send_file(result)
|
8
10
|
assert(@response.body.is_a? Proc)
|
9
11
|
require 'stringio'
|
@@ -13,4 +15,5 @@ class ActiveSupport::TestCase
|
|
13
15
|
puts "OUT: #{output.output}"
|
14
16
|
assert_equal(result, output.string)
|
15
17
|
end
|
18
|
+
|
16
19
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
module ThemesForRails
|
4
|
+
class ViewHelpersTest < ActionController::IntegrationTest
|
5
|
+
include ThemesForRails::ViewHelpers
|
6
|
+
|
7
|
+
include ActionView::Helpers::AssetTagHelper
|
8
|
+
include ERB::Util
|
9
|
+
include ActionView::Helpers::TagHelper
|
10
|
+
|
11
|
+
def theme_name
|
12
|
+
'default'
|
13
|
+
end
|
14
|
+
|
15
|
+
def config
|
16
|
+
@config ||= stub({:perform_caching => false, :asset_path => "/assets", :asset_host => ''})
|
17
|
+
end
|
18
|
+
|
19
|
+
should 'delegate to stylesheet_link_tag' do
|
20
|
+
assert theme_stylesheet_link_tag('cuac.css').include?('media="screen"')
|
21
|
+
end
|
22
|
+
|
23
|
+
should 'delegate options (lazy testing, I know)' do
|
24
|
+
assert theme_stylesheet_link_tag('cuac.css', :media => 'print').include?('media="print"')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
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.
|
8
|
+
s.version = "0.4.0"
|
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{
|
12
|
+
s.date = %q{2011-01-14}
|
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 = [
|
@@ -26,12 +26,12 @@ Gem::Specification.new do |s|
|
|
26
26
|
"Rakefile",
|
27
27
|
"TODO.textile",
|
28
28
|
"init.rb",
|
29
|
-
"lib/generators/
|
30
|
-
"lib/generators/
|
31
|
-
"lib/generators/
|
32
|
-
"lib/generators/
|
33
|
-
"lib/generators/
|
34
|
-
"lib/generators/
|
29
|
+
"lib/generators/themes_for_rails/install_generator.rb",
|
30
|
+
"lib/generators/themes_for_rails/templates/theme/images/.gitkeep",
|
31
|
+
"lib/generators/themes_for_rails/templates/theme/javascripts/.gitkeep",
|
32
|
+
"lib/generators/themes_for_rails/templates/theme/stylesheets/.gitkeep",
|
33
|
+
"lib/generators/themes_for_rails/templates/theme/views/layouts/.gitkeep",
|
34
|
+
"lib/generators/themes_for_rails/theme_generator.rb",
|
35
35
|
"lib/tasks/themes_for_rails.rake",
|
36
36
|
"lib/themes_for_rails.rb",
|
37
37
|
"lib/themes_for_rails/assets_controller.rb",
|
@@ -95,6 +95,7 @@ Gem::Specification.new do |s|
|
|
95
95
|
"test/dummy_app/themes/default/images/logo.png",
|
96
96
|
"test/dummy_app/themes/default/images/nested/logo.png",
|
97
97
|
"test/dummy_app/themes/default/javascripts/app.js",
|
98
|
+
"test/dummy_app/themes/default/stylesheets/images/logo.png",
|
98
99
|
"test/dummy_app/themes/default/stylesheets/style.css",
|
99
100
|
"test/dummy_app/themes/default/stylesheets/style2.css",
|
100
101
|
"test/dummy_app/themes/default/views/layouts/default.html.erb",
|
@@ -103,6 +104,7 @@ Gem::Specification.new do |s|
|
|
103
104
|
"test/support/extensions.rb",
|
104
105
|
"test/test_helper.rb",
|
105
106
|
"test/themes_for_rails_test.rb",
|
107
|
+
"test/view_helpers_test.rb",
|
106
108
|
"themes_for_rails.gemspec"
|
107
109
|
]
|
108
110
|
s.homepage = %q{http://github.com/lucasefe/themes_for_rails}
|
@@ -132,7 +134,8 @@ Gem::Specification.new do |s|
|
|
132
134
|
"test/routes_test.rb",
|
133
135
|
"test/support/extensions.rb",
|
134
136
|
"test/test_helper.rb",
|
135
|
-
"test/themes_for_rails_test.rb"
|
137
|
+
"test/themes_for_rails_test.rb",
|
138
|
+
"test/view_helpers_test.rb"
|
136
139
|
]
|
137
140
|
|
138
141
|
if s.respond_to? :specification_version then
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
7
|
+
- 4
|
8
|
+
- 0
|
9
|
+
version: 0.4.0
|
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:
|
17
|
+
date: 2011-01-14 00:00:00 -03:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -37,12 +37,12 @@ files:
|
|
37
37
|
- Rakefile
|
38
38
|
- TODO.textile
|
39
39
|
- init.rb
|
40
|
-
- lib/generators/
|
41
|
-
- lib/generators/
|
42
|
-
- lib/generators/
|
43
|
-
- lib/generators/
|
44
|
-
- lib/generators/
|
45
|
-
- lib/generators/
|
40
|
+
- lib/generators/themes_for_rails/install_generator.rb
|
41
|
+
- lib/generators/themes_for_rails/templates/theme/images/.gitkeep
|
42
|
+
- lib/generators/themes_for_rails/templates/theme/javascripts/.gitkeep
|
43
|
+
- lib/generators/themes_for_rails/templates/theme/stylesheets/.gitkeep
|
44
|
+
- lib/generators/themes_for_rails/templates/theme/views/layouts/.gitkeep
|
45
|
+
- lib/generators/themes_for_rails/theme_generator.rb
|
46
46
|
- lib/tasks/themes_for_rails.rake
|
47
47
|
- lib/themes_for_rails.rb
|
48
48
|
- lib/themes_for_rails/assets_controller.rb
|
@@ -106,6 +106,7 @@ files:
|
|
106
106
|
- test/dummy_app/themes/default/images/logo.png
|
107
107
|
- test/dummy_app/themes/default/images/nested/logo.png
|
108
108
|
- test/dummy_app/themes/default/javascripts/app.js
|
109
|
+
- test/dummy_app/themes/default/stylesheets/images/logo.png
|
109
110
|
- test/dummy_app/themes/default/stylesheets/style.css
|
110
111
|
- test/dummy_app/themes/default/stylesheets/style2.css
|
111
112
|
- test/dummy_app/themes/default/views/layouts/default.html.erb
|
@@ -114,6 +115,7 @@ files:
|
|
114
115
|
- test/support/extensions.rb
|
115
116
|
- test/test_helper.rb
|
116
117
|
- test/themes_for_rails_test.rb
|
118
|
+
- test/view_helpers_test.rb
|
117
119
|
- themes_for_rails.gemspec
|
118
120
|
has_rdoc: true
|
119
121
|
homepage: http://github.com/lucasefe/themes_for_rails
|
@@ -170,3 +172,4 @@ test_files:
|
|
170
172
|
- test/support/extensions.rb
|
171
173
|
- test/test_helper.rb
|
172
174
|
- test/themes_for_rails_test.rb
|
175
|
+
- test/view_helpers_test.rb
|