sections_rails 0.2.0 → 0.2.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.
|
@@ -31,10 +31,8 @@ class SectionGenerator < Rails::Generators::Base
|
|
|
31
31
|
def split_path
|
|
32
32
|
split_names = name.split '/'
|
|
33
33
|
filename = split_names[-1]
|
|
34
|
-
directory =
|
|
34
|
+
directory = split_names[0..-2].join '/'
|
|
35
35
|
directory += '/' if directory.size > 0
|
|
36
|
-
p directory
|
|
37
|
-
p filename
|
|
38
36
|
[directory, filename]
|
|
39
37
|
end
|
|
40
38
|
|
|
@@ -15,8 +15,9 @@ namespace :sections do
|
|
|
15
15
|
# Create the require file for application.js.
|
|
16
16
|
File.open "app/assets/javascripts/application_sections.js", 'w' do |file|
|
|
17
17
|
sections.each do |section|
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
|
|
19
|
+
if File.exists?(asset_path section, '.js') || File.exists?(asset_path section, '.js.coffee') || File.exists?(asset_path section, '.coffee')
|
|
20
|
+
file.write "//= require #{require_path section}\n"
|
|
20
21
|
end
|
|
21
22
|
end
|
|
22
23
|
end
|
|
@@ -25,8 +26,8 @@ namespace :sections do
|
|
|
25
26
|
File.open "app/assets/stylesheets/application_sections.css", 'w' do |file|
|
|
26
27
|
file.write "/* \n"
|
|
27
28
|
sections.each do |section|
|
|
28
|
-
if File.exists?
|
|
29
|
-
file.write " *= require
|
|
29
|
+
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')
|
|
30
|
+
file.write " *= require #{require_path section}\n"
|
|
30
31
|
end
|
|
31
32
|
end
|
|
32
33
|
file.write " */"
|
|
@@ -91,7 +92,9 @@ namespace :sections do
|
|
|
91
92
|
Dir.entries(File.join(root, dir)).each do |view_file|
|
|
92
93
|
next if ['.', '..'].include? view_file
|
|
93
94
|
next if view_file[-4..-1] == '.swp'
|
|
94
|
-
|
|
95
|
+
view_path = File.join(dir, view_file)
|
|
96
|
+
next if File.directory? "#{root}/#{view_path}"
|
|
97
|
+
result << view_path
|
|
95
98
|
end
|
|
96
99
|
end
|
|
97
100
|
result
|
|
@@ -108,7 +111,9 @@ namespace :sections do
|
|
|
108
111
|
|
|
109
112
|
# Returns an array with the name of all sections in the given view source.
|
|
110
113
|
def find_sections_in_view view_text
|
|
111
|
-
view_text.scan(/<%=\s*section\s+['":](.*?)['"]?\s*%>/).flatten.sort.uniq
|
|
114
|
+
erb_sections = view_text.scan(/<%=\s*section\s+['":](.*?)['"]?\s*%>/).flatten.sort.uniq
|
|
115
|
+
haml_sections = view_text.scan(/\=\s*section\s+['":](.*?)['"]?$/).flatten.sort.uniq
|
|
116
|
+
erb_sections + haml_sections
|
|
112
117
|
end
|
|
113
118
|
|
|
114
119
|
# Returns whether the given file contains the given text somewhere in its content.
|
|
@@ -116,6 +121,23 @@ namespace :sections do
|
|
|
116
121
|
IO.read(file_name) =~ text
|
|
117
122
|
end
|
|
118
123
|
|
|
124
|
+
# Returns the path to the asset in the given section.
|
|
125
|
+
def asset_path section_name, asset_extension = nil, asset_prefix = nil
|
|
126
|
+
split_names = section_name.split '/'
|
|
127
|
+
filename = split_names[-1]
|
|
128
|
+
directory = split_names[0..-2].join '/'
|
|
129
|
+
directory += '/' if directory.size > 0
|
|
130
|
+
"app/sections/#{directory}#{filename}/#{asset_prefix}#{filename}#{asset_extension}"
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
# Returns the relative path to the asset for the asset pipeline.
|
|
134
|
+
def require_path section_name
|
|
135
|
+
split_names = section_name.split '/'
|
|
136
|
+
filename = split_names[-1]
|
|
137
|
+
directory = split_names[0..-2].join '/'
|
|
138
|
+
directory += '/' if directory.size > 0
|
|
139
|
+
"../../sections/#{directory}#{filename}/#{filename}"
|
|
140
|
+
end
|
|
119
141
|
end
|
|
120
142
|
|
|
121
143
|
# Run the 'sections:prepare' rake task automatically before the 'assets:precompile' rake task
|
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.2.
|
|
4
|
+
version: 0.2.1
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -13,7 +13,7 @@ date: 2012-05-26 00:00:00.000000000 Z
|
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: rails
|
|
16
|
-
requirement: &
|
|
16
|
+
requirement: &70206585078040 !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: *70206585078040
|
|
25
25
|
- !ruby/object:Gem::Dependency
|
|
26
26
|
name: rspec
|
|
27
|
-
requirement: &
|
|
27
|
+
requirement: &70206585077540 !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: *70206585077540
|
|
36
36
|
- !ruby/object:Gem::Dependency
|
|
37
37
|
name: sqlite3
|
|
38
|
-
requirement: &
|
|
38
|
+
requirement: &70206585076960 !ruby/object:Gem::Requirement
|
|
39
39
|
none: false
|
|
40
40
|
requirements:
|
|
41
41
|
- - ! '>='
|
|
@@ -43,7 +43,7 @@ dependencies:
|
|
|
43
43
|
version: '0'
|
|
44
44
|
type: :development
|
|
45
45
|
prerelease: false
|
|
46
|
-
version_requirements: *
|
|
46
|
+
version_requirements: *70206585076960
|
|
47
47
|
description: Sections_rails adds infrastructure to the view layer of Ruby on Rails.
|
|
48
48
|
It allows to define and use the HTML, CSS, and JavaScript code of dedicated sections
|
|
49
49
|
of pages together in one place.
|