sections_rails 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/generators/section_generator.rb +36 -8
- data/lib/sections_rails/version.rb +1 -1
- data/lib/sections_rails.rb +17 -8
- metadata +8 -8
@@ -1,24 +1,52 @@
|
|
1
1
|
# Generates a new section.
|
2
2
|
class SectionGenerator < Rails::Generators::Base
|
3
|
-
|
4
3
|
argument :name, :type => :string
|
5
4
|
|
6
5
|
def create_folder
|
7
|
-
empty_directory
|
6
|
+
empty_directory directory_path
|
8
7
|
end
|
9
8
|
|
10
9
|
def create_partial
|
11
|
-
|
12
|
-
|
10
|
+
directory, filename = split_path
|
11
|
+
create_file "#{asset_base_path '_'}.html.haml",
|
12
|
+
".#{filename}\n -# DOM content goes here.\n"
|
13
13
|
end
|
14
14
|
|
15
15
|
def create_coffee_file
|
16
|
-
|
17
|
-
|
16
|
+
directory, filename = split_path
|
17
|
+
create_file "#{asset_base_path}.coffee",
|
18
|
+
"class #{filename}\n # Your CoffeeScript code goes here.\n"
|
18
19
|
end
|
19
20
|
|
20
21
|
def create_sass_file
|
21
|
-
|
22
|
-
|
22
|
+
directory, filename = split_path
|
23
|
+
create_file "#{asset_base_path}.sass",
|
24
|
+
".#{filename}\n /* Your SASS goes here. */\n"
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
# Returns an array [directory, filename] of the given filename.
|
31
|
+
def split_path
|
32
|
+
split_names = name.split '/'
|
33
|
+
filename = split_names[-1]
|
34
|
+
directory = (split_names.size > 1 ? split_names[0..-2] : []).join '/'
|
35
|
+
directory += '/' if directory.size > 0
|
36
|
+
p directory
|
37
|
+
p filename
|
38
|
+
[directory, filename]
|
39
|
+
end
|
40
|
+
|
41
|
+
# Returns the path for the directory of the section.
|
42
|
+
def directory_path
|
43
|
+
directory, filename = split_path
|
44
|
+
"app/sections/#{directory}#{filename}"
|
45
|
+
end
|
46
|
+
|
47
|
+
# Returns the base path of the file, i.e. '/app/sections/admin/foo/foo'.
|
48
|
+
def asset_base_path file_prefix = nil
|
49
|
+
directory, filename = split_path
|
50
|
+
"#{directory_path}/#{file_prefix}#{filename}"
|
23
51
|
end
|
24
52
|
end
|
data/lib/sections_rails.rb
CHANGED
@@ -2,22 +2,31 @@ module SectionsRails
|
|
2
2
|
|
3
3
|
require "sections_rails/railtie" if defined?(Rails)
|
4
4
|
|
5
|
-
def section
|
5
|
+
def section combined_name
|
6
6
|
out = []
|
7
|
-
|
7
|
+
|
8
|
+
# Split the parameter into file name and directory name.
|
9
|
+
split_names = combined_name.to_s.split '/'
|
10
|
+
filename = split_names[-1]
|
11
|
+
directory = (split_names.size > 1 ? split_names[0..-2] : []).join '/'
|
12
|
+
directory += '/' if directory.size > 0
|
13
|
+
|
14
|
+
directory_path = "#{Rails.root}/app/sections/#{directory}#{filename}" # Directory of section: /app/sections/admin/logo
|
15
|
+
file_path = "#{directory_path}/#{filename}" # Base path of filename in section: /app/sections/admin/logo/logo
|
16
|
+
|
8
17
|
|
9
18
|
# Add assets of section when in dev mode.
|
10
19
|
if Rails.env != 'production'
|
11
|
-
out << javascript_include_tag("#{
|
12
|
-
out << stylesheet_link_tag("#{
|
20
|
+
out << javascript_include_tag("#{directory}#{filename}/#{filename}") if File.exists?("#{file_path}.js") || File.exists?("#{file_path}.js.coffee") || File.exists?("#{file_path}.coffee")
|
21
|
+
out << stylesheet_link_tag("#{directory}#{filename}/#{filename}") if File.exists?("#{file_path}.css") || File.exists?("#{file_path}.css.scss") || File.exists?("#{file_path}.css.sass") || File.exists?("#{file_path}.scss") || File.exists?("#{file_path}.sass")
|
13
22
|
end
|
14
23
|
|
15
24
|
# Render the section partial into the view.
|
16
|
-
|
17
|
-
if File.exists?("#{
|
18
|
-
out << render(:partial => "/../sections/#{
|
25
|
+
partial_path = "#{directory_path}/_#{filename}.html"
|
26
|
+
if File.exists?("#{partial_path}.erb") || File.exists?("#{partial_path}.haml")
|
27
|
+
out << render(:partial => "/../sections/#{directory}#{filename}/#{filename}")
|
19
28
|
else
|
20
|
-
out << content_tag(:div, '', :class =>
|
29
|
+
out << content_tag(:div, '', :class => filename)
|
21
30
|
end
|
22
31
|
|
23
32
|
out.join("\n").html_safe
|
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.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-05-
|
12
|
+
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: &70246963972680 !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: *70246963972680
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &70246963971340 !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: *70246963971340
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: sqlite3
|
38
|
-
requirement: &
|
38
|
+
requirement: &70246963970600 !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: *70246963970600
|
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.
|