sections_rails 0.6.3 → 0.6.4
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.
@@ -7,17 +7,18 @@ module SectionsRails
|
|
7
7
|
include ActionView::Helpers::RenderingHelper
|
8
8
|
|
9
9
|
# TODO(KG): remove unnessessary.
|
10
|
-
attr_reader :asset_path, :css, :directory_name, :filename, :
|
10
|
+
attr_reader :asset_path, :css, :directory_name, :filename, :absolute_asset_path, :js, :locals, :partial, :partial_path, :path # NOTE (SZ): too many? :)
|
11
11
|
|
12
|
-
def initialize section_name, rails_obj, options = {}
|
12
|
+
def initialize section_name, rails_obj = nil, options = {}
|
13
13
|
section_name = section_name.to_s
|
14
14
|
|
15
15
|
# Helpers for filenames.
|
16
|
-
@filename = File.basename
|
17
|
-
@directory_name = File.dirname
|
18
|
-
@
|
19
|
-
@
|
20
|
-
@
|
16
|
+
@filename = File.basename section_name, '.*'
|
17
|
+
@directory_name = File.dirname section_name
|
18
|
+
@directory_name = '' if @directory_name == '.'
|
19
|
+
@asset_path = @directory_name != '' ? File.join(@directory_name, @filename, @filename) : File.join(@filename, @filename)
|
20
|
+
@absolute_asset_path = File.join Rails.root, SectionsRails.config.path, @asset_path
|
21
|
+
@partial_path = File.join Rails.root, SectionsRails.config.path, @directory_name, @filename, "_#{@filename}"
|
21
22
|
|
22
23
|
# Options.
|
23
24
|
@js = options[:js]
|
@@ -29,23 +30,41 @@ module SectionsRails
|
|
29
30
|
@rails_obj = rails_obj
|
30
31
|
end
|
31
32
|
|
33
|
+
def find_existing_filename basename, extensions
|
34
|
+
extensions.each do |ext|
|
35
|
+
path = "#{@absolute_asset_path}.#{ext}"
|
36
|
+
return path if File.exists? path
|
37
|
+
end
|
38
|
+
nil
|
39
|
+
end
|
40
|
+
|
41
|
+
# Returns the filename of the partial of this section, or nil if this section has no partial.
|
42
|
+
def find_partial_filename
|
43
|
+
find_existing_filename @partial_path, SectionsRails.config.partial_extensions
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
# TODO: replace this with find_asset.
|
32
48
|
def has_asset? *extensions
|
33
49
|
extensions.flatten.each do |ext|
|
34
|
-
return true if File.exists?("#{@
|
50
|
+
return true if File.exists?("#{@absolute_asset_path}.#{ext}")
|
35
51
|
end
|
36
52
|
false
|
37
53
|
end
|
38
54
|
|
55
|
+
# TODO: replace this with find_asset.
|
39
56
|
def has_default_js_asset?
|
40
57
|
has_asset? SectionsRails.config.js_extensions
|
41
58
|
end
|
42
59
|
|
60
|
+
# TODO: replace this with find_asset.
|
43
61
|
def has_default_style_asset?
|
44
62
|
has_asset? SectionsRails.config.css_extensions
|
45
63
|
end
|
46
64
|
|
47
65
|
# Returns whether this section has a template.
|
48
|
-
|
66
|
+
# Deprecated.
|
67
|
+
def has_partial?
|
49
68
|
SectionsRails.config.partial_extensions.each do |ext|
|
50
69
|
return true if File.exists?("#{@partial_path}.#{ext}")
|
51
70
|
end
|
@@ -89,7 +108,7 @@ module SectionsRails
|
|
89
108
|
when nil
|
90
109
|
# partial: nil given --> render default partial
|
91
110
|
|
92
|
-
if self.
|
111
|
+
if self.has_partial?
|
93
112
|
result << @rails_obj.render(:partial => asset_path, :locals => locals)
|
94
113
|
else
|
95
114
|
result << @rails_obj.content_tag(:div, '', :class => filename)
|
@@ -3,7 +3,7 @@ namespace :sections do
|
|
3
3
|
|
4
4
|
desc "Prepares the assets for precompilation in a setup with a single application.js file"
|
5
5
|
task :prepare do
|
6
|
-
|
6
|
+
print "\nPreparing sections assets ..." ; STDOUT.flush
|
7
7
|
|
8
8
|
# Find all sections used in the views.
|
9
9
|
sections = find_all_views('app/views').map do |view|
|
@@ -33,7 +33,7 @@ namespace :sections do
|
|
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
|
-
file.write "
|
36
|
+
file.write "/*\n"
|
37
37
|
sections.each do |section|
|
38
38
|
if File.exists?(asset_path section, '.css') || File.exists?(asset_path section, '.css.scss') || File.exists?(asset_path section, '.css.sass') || File.exists?(asset_path section, '.scss') || File.exists?(asset_path section, '.sass')
|
39
39
|
file.write " *= require #{require_path section}\n"
|
@@ -42,7 +42,7 @@ namespace :sections do
|
|
42
42
|
file.write " */"
|
43
43
|
end
|
44
44
|
|
45
|
-
puts "
|
45
|
+
puts " done.\n\n"
|
46
46
|
end
|
47
47
|
|
48
48
|
desc "Prepares the assets for precompilation in a setup with multiple files per page."
|
@@ -121,9 +121,13 @@ namespace :sections do
|
|
121
121
|
|
122
122
|
|
123
123
|
def find_sections_in_section section_name
|
124
|
-
|
125
|
-
|
126
|
-
|
124
|
+
section = SectionsRails::Section.new section_name
|
125
|
+
partial_path = section.find_partial_filename
|
126
|
+
if partial_path
|
127
|
+
find_sections IO.read partial_path
|
128
|
+
else
|
129
|
+
[]
|
130
|
+
end
|
127
131
|
end
|
128
132
|
|
129
133
|
# Returns the path to the asset in the given section.
|
@@ -3,16 +3,48 @@ require "spec_helper"
|
|
3
3
|
# TODO(SZ): missing specs.
|
4
4
|
describe SectionsRails::Section do
|
5
5
|
before(:each) { Rails.stub(:root).and_return('/rails_root/') }
|
6
|
-
subject { SectionsRails::Section.new 'folder/section' }
|
6
|
+
subject { SectionsRails::Section.new 'folder/section', nil }
|
7
7
|
|
8
8
|
describe 'initialize' do
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
9
|
+
|
10
|
+
context 'with section in folder' do
|
11
|
+
its(:filename) { should == 'section' }
|
12
|
+
its(:directory_name) { should == 'folder' }
|
13
|
+
its(:asset_path) { should == 'folder/section/section' }
|
14
|
+
its(:absolute_asset_path) { should == '/rails_root/app/sections/folder/section/section' }
|
15
|
+
its(:partial_path) { should == '/rails_root/app/sections/folder/section/_section' }
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'without folder' do
|
19
|
+
subject { SectionsRails::Section.new 'section', nil }
|
20
|
+
its(:filename) { should == 'section' }
|
21
|
+
its(:directory_name) { should == '' }
|
22
|
+
its(:asset_path) { should == 'section/section' }
|
23
|
+
its(:absolute_asset_path) { should == '/rails_root/app/sections/section/section' }
|
24
|
+
its(:partial_path) { should == '/rails_root/app/sections/section/_section' }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe 'find_partial_filename' do
|
29
|
+
it 'looks for all known types of partials' do
|
30
|
+
File.should_receive(:exists?).with("/rails_root/app/sections/folder/section/section.html.erb").and_return(false)
|
31
|
+
File.should_receive(:exists?).with("/rails_root/app/sections/folder/section/section.html.haml").and_return(false)
|
32
|
+
subject.find_partial_filename
|
33
|
+
end
|
34
|
+
|
35
|
+
it "returns nil if it doesn't find any assets" do
|
36
|
+
File.should_receive(:exists?).with("/rails_root/app/sections/folder/section/section.html.erb").and_return(false)
|
37
|
+
File.should_receive(:exists?).with("/rails_root/app/sections/folder/section/section.html.haml").and_return(false)
|
38
|
+
subject.find_partial_filename.should be_false
|
39
|
+
end
|
40
|
+
|
41
|
+
it "returns the absolute path to the asset if it finds one" do
|
42
|
+
File.stub(:exists?).and_return(true)
|
43
|
+
subject.find_partial_filename.should == '/rails_root/app/sections/folder/section/section.html.erb'
|
44
|
+
end
|
14
45
|
end
|
15
46
|
|
47
|
+
|
16
48
|
describe "#has_asset?" do
|
17
49
|
|
18
50
|
it "tries filename variations with all given extensions" do
|
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.4
|
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: &70240927714140 !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: *70240927714140
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &70240927713680 !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: *70240927713680
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: sqlite3
|
38
|
-
requirement: &
|
38
|
+
requirement: &70240927712960 !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: *70240927712960
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: guard-rspec
|
49
|
-
requirement: &
|
49
|
+
requirement: &70240927712360 !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: *70240927712360
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rb-fsevent
|
60
|
-
requirement: &
|
60
|
+
requirement: &70240927711800 !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: *70240927711800
|
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.
|