sections_rails 0.0.5 → 0.0.6
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.
- data/README.md +86 -0
- data/lib/sections_rails/version.rb +1 -1
- data/lib/tasks/sections_rails_tasks.rake +32 -8
- metadata +8 -8
- data/README.markdown +0 -97
data/README.md
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
_Sections_rails_ adds a component-oriented infrastructure to the view layer of Ruby on Rails.
|
2
|
+
This allows to define and use the HTML, CSS, and JavaScript code of dedicated
|
3
|
+
sections of web pages together in one place.
|
4
|
+
|
5
|
+
|
6
|
+
# Example
|
7
|
+
|
8
|
+
Let's take the navigation menu within a web site as an example section.
|
9
|
+
It consists of certain HTML, CSS, and JavaScript code as well as image resources.
|
10
|
+
These assets must be loaded on every page that this navigation menu is visible on,
|
11
|
+
and should be removed when the navigation menu is removed from the site.
|
12
|
+
|
13
|
+
_Sections_rails_ allows to define these assets together, as a _section_ inside the _/app_ folder:
|
14
|
+
|
15
|
+
/app/sections/menu/_menu.html.erb
|
16
|
+
menu.css
|
17
|
+
menu.js
|
18
|
+
|
19
|
+
To display this menu, simply do this in your view:
|
20
|
+
|
21
|
+
```erb
|
22
|
+
<%= section :menu %>
|
23
|
+
```
|
24
|
+
|
25
|
+
The _section_ helper inserts the partial as well as the JS and CSS files from _/app/sections/menu_ at this location.
|
26
|
+
It does the right thing in all circumstances: In development mode, it inserts the individual assets.
|
27
|
+
In production mode, it inserts the assets to the main _application.js_ bundle.
|
28
|
+
|
29
|
+
|
30
|
+
# Installation
|
31
|
+
|
32
|
+
In your Gemfile:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
gem 'sections_rails'
|
36
|
+
```
|
37
|
+
|
38
|
+
Then set up the directory structure:
|
39
|
+
|
40
|
+
```bash
|
41
|
+
$ rails generate sections
|
42
|
+
```
|
43
|
+
|
44
|
+
The generator does the following things:
|
45
|
+
|
46
|
+
1. It creates a new folder __/app/sections__,
|
47
|
+
in which you put the source code for the different sections.
|
48
|
+
|
49
|
+
2. It adds the folder _/app/sections_ to the asset pipeline by inserting this line into your _application.rb_ file:
|
50
|
+
|
51
|
+
config.assets.paths << 'app/sections'
|
52
|
+
|
53
|
+
3. It optionally creates a demo section called _hello_world_ that you can try out as described below.
|
54
|
+
|
55
|
+
|
56
|
+
In it's current prototypical implementation, _Sections_rails_ also creates empty asset container files:
|
57
|
+
__application_sections.js__ and __application_sections.css__.
|
58
|
+
Make sure you require them from your main _application.js_ and _application.css_ files.
|
59
|
+
They are used only when running _rake assets:precompile_ during deployment, and should be checked in and stay the way they are.
|
60
|
+
|
61
|
+
|
62
|
+
# Usage
|
63
|
+
|
64
|
+
To use the "hello_world" section created by the sections generator, simply add it to the view:
|
65
|
+
|
66
|
+
```erb
|
67
|
+
<%= section :hello_world %>
|
68
|
+
```
|
69
|
+
|
70
|
+
If your section renders itself completely in JavaScript, you can omit its partial file.
|
71
|
+
In this case, the _sections_ helper creates an empty div in the view.
|
72
|
+
|
73
|
+
```html
|
74
|
+
<div class="hello_world"></div>
|
75
|
+
```
|
76
|
+
|
77
|
+
|
78
|
+
# Missing features
|
79
|
+
|
80
|
+
_Sections_rails_ is in prototypical development and far from complete. Missing features are:
|
81
|
+
|
82
|
+
* Support for multiple application assets, for example page-specific compiled asset files instead of one global one.
|
83
|
+
* Support for assets in different formats like CoffeeScript, Haml, Sass etc.
|
84
|
+
* Support for serverside controller logic for sections, for example by integrating with https://github.com/apotonick/cells.
|
85
|
+
* More natural integration into the asset pipeline.
|
86
|
+
|
@@ -14,9 +14,6 @@ namespace :sections do
|
|
14
14
|
|
15
15
|
# Create the require file for application.js.
|
16
16
|
File.open "app/assets/javascripts/application_sections.js", 'w' do |file|
|
17
|
-
file.write "// THIS FILE IS AUTOMATICALLY CREATED BY THE SECTIONS PLUGIN.\n"
|
18
|
-
file.write "// PLEASE DO NOT MODIFY MANUALLY.\n"
|
19
|
-
file.write "//\n"
|
20
17
|
sections.each do |section|
|
21
18
|
if File.exists? "app/sections/#{section}/#{section}.js"
|
22
19
|
file.write "//= require ../../sections/#{section}/#{section} \n"
|
@@ -27,15 +24,12 @@ namespace :sections do
|
|
27
24
|
# Create the require file for application.css.
|
28
25
|
File.open "app/assets/stylesheets/application_sections.css", 'w' do |file|
|
29
26
|
file.write "/* \n"
|
30
|
-
file.write " * THIS FILE IS AUTOMATICALLY CREATED BY THE SECTIONS PLUGIN.\n"
|
31
|
-
file.write " * PLEASE DO NOT MODIFY MANUALLY.\n"
|
32
|
-
file.write " *\n"
|
33
27
|
sections.each do |section|
|
34
28
|
if File.exists? "app/sections/#{section}/#{section}.css"
|
35
29
|
file.write " *= require ../../sections/#{section}/#{section}\n"
|
36
30
|
end
|
37
31
|
end
|
38
|
-
file.write "*/"
|
32
|
+
file.write " */"
|
39
33
|
end
|
40
34
|
|
41
35
|
puts "Preparing section assets done.\n\n"
|
@@ -61,6 +55,33 @@ namespace :sections do
|
|
61
55
|
end
|
62
56
|
end
|
63
57
|
|
58
|
+
desc 'Creates empty asset containers'
|
59
|
+
task :reset_asset_containers do
|
60
|
+
puts "Cleaning up section asset containers."
|
61
|
+
|
62
|
+
# Clean up JS asset container.
|
63
|
+
File.open "app/assets/javascripts/application_sections.js", 'w' do |file|
|
64
|
+
file.write <<-END_STR
|
65
|
+
// THIS FILE IS AUTOMATICALLY CREATED BY THE SECTIONS PLUGIN
|
66
|
+
// AND MUST BE LOADED BY YOUR PAGE.
|
67
|
+
// PLEASE DO NOT MODIFY IT MANUALLY.
|
68
|
+
//
|
69
|
+
END_STR
|
70
|
+
end
|
71
|
+
|
72
|
+
# Clean up CSS asset container.
|
73
|
+
File.open "app/assets/stylesheets/application_sections.css", 'w' do |file|
|
74
|
+
file.write <<-END_STR
|
75
|
+
/*
|
76
|
+
* THIS FILE IS AUTOMATICALLY CREATED BY THE SECTIONS PLUGIN.
|
77
|
+
* AND MUST BE LOADED BY YOUR PAGE.
|
78
|
+
* PLEASE DO NOT MODIFY MANUALLY.
|
79
|
+
*/
|
80
|
+
END_STR
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
|
64
85
|
# Returns an array with the file name of all views in the given directory.
|
65
86
|
# Views are all files that end in .html.erb
|
66
87
|
def find_all_views root
|
@@ -99,4 +120,7 @@ end
|
|
99
120
|
|
100
121
|
# Run the 'sections:prepare' rake task automatically before the 'assets:precompile' rake task
|
101
122
|
# when the latter is called.
|
102
|
-
Rake::Task['assets:precompile'].enhance ['sections:prepare']
|
123
|
+
Rake::Task['assets:precompile'].enhance ['sections:prepare'] do
|
124
|
+
Rake::Task["sections:reset_asset_containers"].invoke
|
125
|
+
end
|
126
|
+
|
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.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-05-25 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
|
-
requirement: &
|
16
|
+
requirement: &70230652581660 !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: *70230652581660
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &70230652581240 !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: *70230652581240
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: sqlite3
|
38
|
-
requirement: &
|
38
|
+
requirement: &70230652580780 !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: *70230652580780
|
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.
|
@@ -60,7 +60,7 @@ files:
|
|
60
60
|
- lib/tasks/sections_rails_tasks.rake
|
61
61
|
- MIT-LICENSE
|
62
62
|
- Rakefile
|
63
|
-
- README.
|
63
|
+
- README.md
|
64
64
|
- spec/dummy/app/assets/javascripts/application.js
|
65
65
|
- spec/dummy/app/assets/stylesheets/application.css
|
66
66
|
- spec/dummy/app/controllers/application_controller.rb
|
data/README.markdown
DELETED
@@ -1,97 +0,0 @@
|
|
1
|
-
Ruby on Rails provides an amazing infrastructure and conventions for well structured server-side code.
|
2
|
-
It falls, however, short for the view layer.
|
3
|
-
|
4
|
-
_Partials_ provide a nice way to represent the HTML code of individual sections within complex web pages,
|
5
|
-
but no such facilities are available for the corresponding CSS and JavaScript.
|
6
|
-
This leaves the task of organizing the JS and CSS completely up to the user.
|
7
|
-
|
8
|
-
_Sections_rails_ fills this gap by adding infrastructure to the view layer of Ruby on Rails.
|
9
|
-
It allows to define and use the HTML, CSS, and JavaScript code of dedicated
|
10
|
-
sections of pages together in one place.
|
11
|
-
|
12
|
-
|
13
|
-
# Example
|
14
|
-
|
15
|
-
Let's assume a web page has amongst other things a navigation menu.
|
16
|
-
This menu requires certain HTML, CSS, and JavaScript code that is specific to it.
|
17
|
-
_Sections_rails_ allows to define this code as a _section_ inside the _/app_ folder:
|
18
|
-
|
19
|
-
/app/sections/menu/_menu.html.erb
|
20
|
-
menu.css
|
21
|
-
menu.js
|
22
|
-
|
23
|
-
To display this menu, simply do this in your view:
|
24
|
-
|
25
|
-
<%= section :menu %>
|
26
|
-
|
27
|
-
This inserts the partial as well as the JS and CSS files from _/app/sections/menu_ at this location.
|
28
|
-
|
29
|
-
|
30
|
-
# Installation
|
31
|
-
|
32
|
-
In your Gemfile:
|
33
|
-
|
34
|
-
gem 'sections_rails'
|
35
|
-
|
36
|
-
Then set up the directory structure:
|
37
|
-
|
38
|
-
$ rails generate sections
|
39
|
-
|
40
|
-
The generator does the following things:
|
41
|
-
|
42
|
-
1. It creates a new folder __/app/sections__,
|
43
|
-
in which you put the source code for the different sections.
|
44
|
-
|
45
|
-
2. It adds the folder _/app/sections_ to the asset pipeline by inserting this line into your _application.rb_ file:
|
46
|
-
|
47
|
-
config.assets.paths << 'app/sections'
|
48
|
-
|
49
|
-
3. It optionally creates a demo section called _hello_world_.
|
50
|
-
|
51
|
-
|
52
|
-
# Usage
|
53
|
-
|
54
|
-
To use the "hello_world" section created by the sections generator, simply add it to the view:
|
55
|
-
|
56
|
-
<%= section :hello_world %>
|
57
|
-
|
58
|
-
If your section renders itself completely in JavaScript, you can omit its partial file.
|
59
|
-
In this case, the _sections_ command creates an empty div in the view.
|
60
|
-
|
61
|
-
<div class="hello_world"></div>
|
62
|
-
|
63
|
-
|
64
|
-
## Asset precompilation
|
65
|
-
|
66
|
-
_Sections_rails_ provides facilities to include the assets of sections in the global asset
|
67
|
-
bundles for production mode.
|
68
|
-
|
69
|
-
1. Run __rake sections:prepare__
|
70
|
-
|
71
|
-
This rake task creates helper files that tell the asset pipeline about the assets of the different sections.
|
72
|
-
|
73
|
-
* _/app/assets/javascripts/application_sections.js_ links to all JS files of all sections.
|
74
|
-
* _/app/assets/stylesheets/application_sections.js_ links to all CSS files of all sections.
|
75
|
-
|
76
|
-
2. Include the generated helper files into your _application.js_ and _application.css_ files.
|
77
|
-
|
78
|
-
In application.js:
|
79
|
-
|
80
|
-
//= require application_sections
|
81
|
-
|
82
|
-
In application.css:
|
83
|
-
|
84
|
-
/*= require application_sections */
|
85
|
-
|
86
|
-
3. Run __rake assets:precompile__ as usual.
|
87
|
-
|
88
|
-
|
89
|
-
# Missing features
|
90
|
-
|
91
|
-
_Sections_rails_ is in early development and far from complete. Missing features are:
|
92
|
-
|
93
|
-
* Support for multiple assets, and assets per section
|
94
|
-
* support for assets in different formats like CoffeeScript, Haml, Sass etc.
|
95
|
-
* Support for page-specific compiled asset files instead of one global one
|
96
|
-
* Better integration into the asset precompilation workflow.
|
97
|
-
* Include serverside controller logic for sections by integrating with https://github.com/apotonick/cells or something comparable
|