sections_rails 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,9 @@
1
1
  class SectionsGenerator < Rails::Generators::Base
2
2
 
3
3
  def create_sections_folder
4
+ say ''
5
+ say ' STEP 1: Creating sections folder'
6
+ say ''
4
7
  empty_directory "app/sections"
5
8
  inject_into_file 'config/application.rb',
6
9
  " config.assets.paths << 'app/sections'\n",
@@ -12,7 +15,45 @@ class SectionsGenerator < Rails::Generators::Base
12
15
  say ''
13
16
  end
14
17
 
18
+ def create_section_assets
19
+ say ''
20
+ say 'STEP 2: Creating asset manifests.'
21
+ say ''
22
+ create_file 'app/assets/javascripts/application_sections.js', <<-END_STR
23
+ // THIS FILE IS AUTOMATICALLY CREATED BY THE SECTIONS PLUGIN
24
+ // AND MUST BE LOADED BY YOUR PAGE.
25
+ // PLEASE DO NOT MODIFY IT MANUALLY.
26
+ //
27
+ END_STR
28
+
29
+ create_file 'app/assets/stylesheets/application_sections.css', <<-END_STR
30
+ /*
31
+ * THIS FILE IS AUTOMATICALLY CREATED BY THE SECTIONS PLUGIN.
32
+ * AND MUST BE LOADED BY YOUR PAGE.
33
+ * PLEASE DO NOT MODIFY MANUALLY.
34
+ */
35
+ END_STR
36
+
37
+ say ''
38
+ say ' I have created two files to reference the assets from the sections.'
39
+ say ' * '
40
+ say 'app/assets/javascripts/application_sections.js', Thor::Shell::Color::BOLD
41
+ say ' * '
42
+ say 'app/assets/stylesheets/application_sections.css', Thor::Shell::Color::BOLD
43
+ say ''
44
+ say ' They should be checked into your code repository the way they are, and remain that way.'
45
+ say ' When running "rake assets:precompile" during deployment,'
46
+ say ' they will be updated with the actually used assets for proper operation in production mode.'
47
+ say ''
48
+ say ' You must make sure they are loaded into the asset pipeline, for example by'
49
+ say ' requiring them in application.js and application.css.'
50
+ say ''
51
+ end
52
+
15
53
  def create_sample_section
54
+ say ''
55
+ say 'STEP 3: Creating a sample section.'
56
+ say ''
16
57
 
17
58
  # Ask the user.
18
59
  return unless ['', 'y', 'yes'].include? ask('Do you want to create a sample section? [Yn]').downcase
@@ -22,11 +63,15 @@ class SectionsGenerator < Rails::Generators::Base
22
63
 
23
64
  # Create the partial.
24
65
  create_file "app/sections/hello_world/_hello_world.html.erb", <<-END_STR
25
- <!-- This file contains the HTML for the 'hello world' section. -->
66
+ <%# This file contains the HTML for the 'hello world' section. %>
26
67
 
27
68
  <div class="hello_world">
28
69
  <h2>Hello World!</h2>
29
- This is content inside the hello world section!
70
+ This is content defined by the hello world section.<br>
71
+ It is styled by CSS from the section. <br>
72
+ <br>
73
+ Click on this section.<br>
74
+ The behavior comes from the section's JavaScript file.<br>
30
75
  </div>
31
76
  END_STR
32
77
 
@@ -39,7 +84,7 @@ class SectionsGenerator < Rails::Generators::Base
39
84
  * in this case the ".hello" class.
40
85
  */
41
86
 
42
- .hello_world { width: 300px; padding: 0 2ex 2ex; border: 2px dotted red; background-color: yellow; }
87
+ .hello_world { width: 350px; padding: 0 2ex 2ex; border: 2px dotted red; background-color: yellow; }
43
88
  .hello_world .h2 { font-size: 1em; margin: 0 0 1ex; padding: 0; }
44
89
  END_STR
45
90
 
@@ -52,17 +97,19 @@ class SectionsGenerator < Rails::Generators::Base
52
97
  * i.e. the <div> with the class 'hello_world'.
53
98
  */
54
99
 
55
- $('.hello_world').click(function() {
56
- alert('The Hello World section says hello to the world! :)');
100
+ $(function() {
101
+ $('.hello_world').click(function() {
102
+ alert('The Hello World section says hello to the world!');
103
+ });
57
104
  });
58
105
  END_STR
59
106
 
60
107
  say ''
61
108
  say ' A sample section has been created in '
62
- say 'app/sections/sample_section', Thor::Shell::Color::BOLD
109
+ say 'app/sections/hello_world', Thor::Shell::Color::BOLD
63
110
  say ' To use it, simply put '
64
- say '<%= section :sample %>', Thor::Shell::Color::BOLD
65
- say ' in your view file.'
111
+ say '<%= section :hello_world %>', Thor::Shell::Color::BOLD
112
+ say ' into a view file.'
66
113
  say ''
67
114
  say ' Happy coding! :)'
68
115
  say ''
@@ -1,3 +1,3 @@
1
1
  module SectionsRails
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -2,6 +2,7 @@ namespace :sections do
2
2
 
3
3
  desc "Prepares the assets for precompilation in a setup with a single application.js file"
4
4
  task :prepare do
5
+ puts "\nPreparing sections assets ..."
5
6
 
6
7
  # Find all views in this app.
7
8
  views = find_all_views 'app/views'
@@ -37,13 +38,7 @@ namespace :sections do
37
38
  file.write "*/"
38
39
  end
39
40
 
40
- # Make sure the require files are properly linked.
41
- unless file_contains 'app/assets/javascripts/application.js', /application_sections/
42
- puts "Please add the 'require' statement to 'application_sections.js' to 'application.js'."
43
- end
44
- unless file_contains 'app/assets/stylesheets/application.css', /application_sections/
45
- puts "Please add the 'require' statement to 'application_sections.css' to 'application.css'."
46
- end
41
+ puts "Preparing section assets done.\n\n"
47
42
  end
48
43
 
49
44
  desc "Prepares the assets for precompilation in a setup with multiple files per page."
@@ -74,6 +69,7 @@ namespace :sections do
74
69
  next if ['.', '..', 'layouts'].include? dir
75
70
  Dir.entries(File.join(root, dir)).each do |view_file|
76
71
  next if ['.', '..'].include? view_file
72
+ next if view_file[-4..-1] == '.swp'
77
73
  result << File.join(dir, view_file)
78
74
  end
79
75
  end
@@ -91,7 +87,7 @@ namespace :sections do
91
87
 
92
88
  # Returns an array with the name of all sections in the given view source.
93
89
  def find_sections_in_view view_text
94
- view_text.scan(/<%= section\s+['"](.*?)['"]\s*%>/).flatten.sort.uniq
90
+ view_text.scan(/<%=\s*section\s+['":](.*?)['"]?\s*%>/).flatten.sort.uniq
95
91
  end
96
92
 
97
93
  # Returns whether the given file contains the given text somewhere in its content.
@@ -100,3 +96,7 @@ namespace :sections do
100
96
  end
101
97
 
102
98
  end
99
+
100
+ # Run the 'sections:prepare' rake task automatically before the 'assets:precompile' rake task
101
+ # when the latter is called.
102
+ Rake::Task['assets:precompile'].enhance ['sections:prepare']
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.0.2
4
+ version: 0.0.3
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: 2011-12-22 00:00:00.000000000Z
12
+ date: 2012-05-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
16
- requirement: &70259722045160 !ruby/object:Gem::Requirement
16
+ requirement: &70256958176400 !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: *70259722045160
24
+ version_requirements: *70256958176400
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &70259722044520 !ruby/object:Gem::Requirement
27
+ requirement: &70256958175980 !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: *70259722044520
35
+ version_requirements: *70256958175980
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: sqlite3
38
- requirement: &70259722043800 !ruby/object:Gem::Requirement
38
+ requirement: &70256958175520 !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: *70259722043800
46
+ version_requirements: *70256958175520
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.
@@ -132,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
132
132
  version: '0'
133
133
  requirements: []
134
134
  rubyforge_project:
135
- rubygems_version: 1.8.12
135
+ rubygems_version: 1.8.10
136
136
  signing_key:
137
137
  specification_version: 3
138
138
  summary: A rails plugin that allows to define the HTML, CSS, and JS for individual
@@ -189,4 +189,3 @@ test_files:
189
189
  - spec/dummy/tmp/cache/assets/D94/460/sprockets%2Fd4ba18ed6ca55f732dba192d4b6036a8
190
190
  - spec/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af
191
191
  - spec/spec_helper.rb
192
- has_rdoc: