sections_rails 0.6.4 → 0.6.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/sections_rails/section.rb +21 -1
- data/lib/sections_rails/version.rb +1 -1
- data/lib/tasks/sections_rails_tasks.rake +11 -10
- data/spec/sections_rails/section_spec.rb +37 -5
- metadata +11 -11
@@ -32,7 +32,7 @@ module SectionsRails
|
|
32
32
|
|
33
33
|
def find_existing_filename basename, extensions
|
34
34
|
extensions.each do |ext|
|
35
|
-
path = "#{
|
35
|
+
path = "#{basename}.#{ext}"
|
36
36
|
return path if File.exists? path
|
37
37
|
end
|
38
38
|
nil
|
@@ -43,6 +43,26 @@ module SectionsRails
|
|
43
43
|
find_existing_filename @partial_path, SectionsRails.config.partial_extensions
|
44
44
|
end
|
45
45
|
|
46
|
+
# Returns the asset_path of asset with the given extensions.
|
47
|
+
def find_asset_path asset_option, extensions
|
48
|
+
return nil if asset_option == false
|
49
|
+
return asset_option if asset_option
|
50
|
+
extensions.each do |ext|
|
51
|
+
file_path = "#{@absolute_asset_path}.#{ext}"
|
52
|
+
return @asset_path if File.exists? file_path
|
53
|
+
end
|
54
|
+
nil
|
55
|
+
end
|
56
|
+
|
57
|
+
# Returns the path to the JS asset of this section, or nil if the section doesn't have one.
|
58
|
+
def find_css_asset_path
|
59
|
+
find_asset_path @css, SectionsRails.config.css_extensions
|
60
|
+
end
|
61
|
+
|
62
|
+
# Returns the path to the JS asset of this section, or nil if the section doesn't have one.
|
63
|
+
def find_js_asset_path
|
64
|
+
find_asset_path @js, SectionsRails.config.js_extensions
|
65
|
+
end
|
46
66
|
|
47
67
|
# TODO: replace this with find_asset.
|
48
68
|
def has_asset? *extensions
|
@@ -7,8 +7,8 @@ namespace :sections do
|
|
7
7
|
|
8
8
|
# Find all sections used in the views.
|
9
9
|
sections = find_all_views('app/views').map do |view|
|
10
|
-
find_sections IO.read"app/views/#{view}"
|
11
|
-
end.flatten
|
10
|
+
find_sections IO.read "app/views/#{view}"
|
11
|
+
end.flatten.sort.uniq
|
12
12
|
|
13
13
|
# Find all sections within the already known sections.
|
14
14
|
i = 0
|
@@ -24,20 +24,20 @@ namespace :sections do
|
|
24
24
|
|
25
25
|
# Create the require file for application.js.
|
26
26
|
File.open "app/assets/javascripts/application_sections.js", 'w' do |file|
|
27
|
-
sections.each do |
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
sections.each do |section_name|
|
28
|
+
section = SectionsRails::Section.new section_name
|
29
|
+
js_asset = section.find_js_asset_path
|
30
|
+
file.write "//= require #{js_asset}\n" if js_asset
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
34
|
# Create the require file for application.css.
|
35
35
|
File.open "app/assets/stylesheets/application_sections.css", 'w' do |file|
|
36
36
|
file.write "/*\n"
|
37
|
-
sections.each do |
|
38
|
-
|
39
|
-
|
40
|
-
|
37
|
+
sections.each do |section_name|
|
38
|
+
section = SectionsRails::Section.new section_name
|
39
|
+
js_asset = section.find_js_asset_path
|
40
|
+
file.write "//= require #{js_asset}\n" if js_asset
|
41
41
|
end
|
42
42
|
file.write " */"
|
43
43
|
end
|
@@ -123,6 +123,7 @@ namespace :sections do
|
|
123
123
|
def find_sections_in_section section_name
|
124
124
|
section = SectionsRails::Section.new section_name
|
125
125
|
partial_path = section.find_partial_filename
|
126
|
+
puts "section #{section_name} has partial #{partial_path}"
|
126
127
|
if partial_path
|
127
128
|
find_sections IO.read partial_path
|
128
129
|
else
|
@@ -26,24 +26,56 @@ describe SectionsRails::Section do
|
|
26
26
|
end
|
27
27
|
|
28
28
|
describe 'find_partial_filename' do
|
29
|
+
|
29
30
|
it 'looks for all known types of partials' do
|
30
|
-
File.should_receive(:exists?).with("/rails_root/app/sections/folder/section/
|
31
|
-
File.should_receive(:exists?).with("/rails_root/app/sections/folder/section/
|
31
|
+
File.should_receive(:exists?).with("/rails_root/app/sections/folder/section/_section.html.erb").and_return(false)
|
32
|
+
File.should_receive(:exists?).with("/rails_root/app/sections/folder/section/_section.html.haml").and_return(false)
|
32
33
|
subject.find_partial_filename
|
33
34
|
end
|
34
35
|
|
35
36
|
it "returns nil if it doesn't find any assets" do
|
36
|
-
File.should_receive(:exists?).with("/rails_root/app/sections/folder/section/
|
37
|
-
File.should_receive(:exists?).with("/rails_root/app/sections/folder/section/
|
37
|
+
File.should_receive(:exists?).with("/rails_root/app/sections/folder/section/_section.html.erb").and_return(false)
|
38
|
+
File.should_receive(:exists?).with("/rails_root/app/sections/folder/section/_section.html.haml").and_return(false)
|
38
39
|
subject.find_partial_filename.should be_false
|
39
40
|
end
|
40
41
|
|
41
42
|
it "returns the absolute path to the asset if it finds one" do
|
42
43
|
File.stub(:exists?).and_return(true)
|
43
|
-
subject.find_partial_filename.should == '/rails_root/app/sections/folder/section/
|
44
|
+
subject.find_partial_filename.should == '/rails_root/app/sections/folder/section/_section.html.erb'
|
44
45
|
end
|
45
46
|
end
|
46
47
|
|
48
|
+
describe 'find_js_asset_path' do
|
49
|
+
it 'tries all different JS asset file types for sections' do
|
50
|
+
SectionsRails.config.js_extensions.each do |ext|
|
51
|
+
File.should_receive(:exists?).with("/rails_root/app/sections/folder/section/section.#{ext}").and_return(false)
|
52
|
+
end
|
53
|
+
subject.find_js_asset_path
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'returns nil if there is no known JS asset file' do
|
57
|
+
SectionsRails.config.js_extensions.each do |ext|
|
58
|
+
File.should_receive(:exists?).with("/rails_root/app/sections/folder/section/section.#{ext}").and_return(false)
|
59
|
+
end
|
60
|
+
subject.find_js_asset_path.should be_false
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'returns the asset path of the JS asset' do
|
64
|
+
File.stub(:exists?).and_return(true)
|
65
|
+
subject.find_js_asset_path.should == 'folder/section/section'
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'returns nil if the file exists but the section has JS assets disabled' do
|
69
|
+
File.stub(:exists?).and_return(true)
|
70
|
+
section = SectionsRails::Section.new 'folder/section', nil, js: false
|
71
|
+
section.find_js_asset_path.should be_false
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'returns the custom JS asset path if one is set' do
|
75
|
+
section = SectionsRails::Section.new 'folder/section', nil, js: 'custom'
|
76
|
+
section.find_js_asset_path.should == 'custom'
|
77
|
+
end
|
78
|
+
end
|
47
79
|
|
48
80
|
describe "#has_asset?" do
|
49
81
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sections_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-06-08 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
|
-
requirement: &
|
16
|
+
requirement: &70295138811940 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '3.1'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70295138811940
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &70295138811220 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70295138811220
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: sqlite3
|
38
|
-
requirement: &
|
38
|
+
requirement: &70295138810700 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70295138810700
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: guard-rspec
|
49
|
-
requirement: &
|
49
|
+
requirement: &70295138810200 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70295138810200
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rb-fsevent
|
60
|
-
requirement: &
|
60
|
+
requirement: &70295138809560 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70295138809560
|
69
69
|
description: Sections_rails adds infrastructure to the view layer of Ruby on Rails.
|
70
70
|
It allows to define and use the HTML, CSS, and JavaScript code of dedicated sections
|
71
71
|
of pages together in one place.
|