sections_rails 0.7.1 → 0.7.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/README.md +82 -92
  2. data/lib/sections_rails/section.rb +11 -174
  3. data/lib/sections_rails/section_asset_rendering.rb +92 -0
  4. data/lib/sections_rails/section_partial_rendering.rb +100 -0
  5. data/lib/sections_rails/version.rb +1 -1
  6. data/lib/sections_rails/view_finder.rb +10 -8
  7. data/lib/sections_rails.rb +1 -1
  8. data/spec/controllers/image_assets_controller_spec.rb +38 -0
  9. data/spec/controllers/partials_controller_spec.rb +25 -11
  10. data/spec/controllers/script_assets_controller_spec.rb +7 -7
  11. data/spec/controllers/style_assets_controller_spec.rb +10 -10
  12. data/spec/controllers/view_types_controller_spec.rb +3 -3
  13. data/spec/dummy/app/controllers/image_assets_controller.rb +14 -0
  14. data/spec/dummy/app/controllers/partials_controller.rb +6 -0
  15. data/spec/dummy/app/views/image_assets/gif.html.erb +1 -0
  16. data/spec/dummy/app/views/image_assets/jpeg.html.erb +1 -0
  17. data/spec/dummy/app/views/image_assets/jpg.html.erb +1 -0
  18. data/spec/dummy/app/views/image_assets/png.html.erb +1 -0
  19. data/spec/dummy/app/views/partials/custom_partial_with_block.html.erb +3 -0
  20. data/spec/dummy/app/views/partials/tag_option.html.erb +1 -0
  21. data/spec/dummy/config/application.rb +4 -3
  22. data/spec/dummy/config/boot.rb +7 -3
  23. data/spec/dummy/config/environments/test.rb +1 -4
  24. data/spec/dummy/db/development.sqlite3 +0 -0
  25. data/spec/dummy/db/test.sqlite3 +0 -0
  26. data/spec/dummy/log/development.log +3204 -16064
  27. data/spec/dummy/log/production.log +61 -0
  28. data/spec/dummy/log/test.log +2041 -0
  29. data/spec/sections_rails/config_spec.rb +31 -0
  30. data/spec/sections_rails/partial_parser_spec.rb +12 -12
  31. data/spec/sections_rails/section_spec.rb +16 -54
  32. data/spec/sections_rails/view_finder_spec.rb +4 -4
  33. data/spec/spec_helper.rb +3 -0
  34. metadata +73 -35
  35. data/spec/dummy/tmp/cache/assets/CB9/B60/sprockets%2Fe7b839a0806e5c20e5018197f56cd656 +0 -0
  36. data/spec/dummy/tmp/cache/assets/CD8/370/sprockets%2F357970feca3ac29060c1e3861e2c0953 +0 -0
  37. data/spec/dummy/tmp/cache/assets/D32/A10/sprockets%2F13fe41fee1fe35b49d145bcc06610705 +0 -0
  38. data/spec/dummy/tmp/cache/assets/D4E/1B0/sprockets%2Ff7cbd26ba1d28d48de824f0e94586655 +0 -0
  39. data/spec/dummy/tmp/cache/assets/D5A/EA0/sprockets%2Fd771ace226fc8215a3572e0aa35bb0d6 +0 -0
  40. data/spec/dummy/tmp/cache/assets/D76/4D0/sprockets%2F8a096b6dd59bfda3e461617a95524eaf +0 -0
  41. data/spec/dummy/tmp/cache/assets/DDC/400/sprockets%2Fcffd775d018f68ce5dba1ee0d951a994 +0 -0
  42. data/spec/dummy/tmp/cache/assets/DE1/6A0/sprockets%2Fcae9aba95894da8a28fa8a5387dc565f +0 -0
  43. data/spec/dummy/tmp/cache/assets/E04/890/sprockets%2F2f5173deea6c795b8fdde723bb4b63af +0 -0
  44. data/spec/dummy/tmp/cache/assets/E1D/010/sprockets%2Fdffad412d86bfdfbb1f307d711da21d3 +0 -0
@@ -19,14 +19,16 @@ module SectionsRails
19
19
  end
20
20
 
21
21
  # Used for :prepare_pages. Not used right now.
22
- def self.parse_views views
23
- result = {}
24
- views_to_parse.each do |view_to_parse|
25
- view_text = IO.read(File.join root, view_to_parse)
26
- result[view_to_parse] = find_sections_in_text view_text
27
- end
28
- result
29
- end
22
+ # def self.parse_views views
23
+ # result = {}
24
+ # views_to_parse.each do |view_to_parse|
25
+ # puts root
26
+
27
+ # view_text = IO.read(File.join root, view_to_parse)
28
+ # result[view_to_parse] = find_sections_in_text view_text
29
+ # end
30
+ # result
31
+ # end
30
32
 
31
33
  end
32
34
  end
@@ -1,7 +1,7 @@
1
1
  module SectionsRails
2
2
  require 'action_view'
3
3
  require "sections_rails/section"
4
- require "sections_rails/railtie" if defined?(Rails)
4
+ require "sections_rails/railtie" #if defined?(Rails)
5
5
 
6
6
  def section name, options = {}, &block
7
7
  SectionsRails::Section.new(name, self, options).render &block
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe ImageAssetsController do
4
+ render_views
5
+
6
+ before :each do
7
+ RSpec::Matchers.define :have_image_tag do |tag_name|
8
+ match do |body|
9
+ body =~ Regexp.new("<img.*src=\"#{tag_name}\"")
10
+ end
11
+ end
12
+ end
13
+
14
+ after :each do
15
+ expect(response).to be_success
16
+ end
17
+
18
+ it 'supports GIF images' do
19
+ get :gif
20
+ expect(response.body).to have_image_tag '/assets/image_assets/gif/pic.gif'
21
+ end
22
+
23
+ it 'supports JPG images' do
24
+ get :jpg
25
+ expect(response.body).to have_image_tag '/assets/image_assets/jpg/pic.jpg'
26
+ end
27
+
28
+ it 'supports JPEG images' do
29
+ get :jpeg
30
+ expect(response.body).to have_image_tag '/assets/image_assets/jpeg/pic.jpeg'
31
+ end
32
+
33
+ it 'supports PNG images' do
34
+ get :png
35
+ expect(response.body).to have_image_tag '/assets/image_assets/png/pic.png'
36
+ end
37
+ end
38
+
@@ -5,24 +5,31 @@ describe PartialsController do
5
5
 
6
6
  describe 'supported partial types' do
7
7
  after :each do
8
- response.should be_success
8
+ expect(response).to be_success
9
9
  end
10
10
 
11
11
  it 'allows to use ERB partials' do
12
12
  get :erb_section
13
- response.body.strip.should == 'ERB partial content'
13
+ expect(response.body.strip).to eql 'ERB partial content'
14
14
  end
15
15
 
16
16
  it 'allows to use HAML partials' do
17
17
  get :haml_section
18
- response.body.strip.should == 'HAML partial content'
18
+ expect(response.body.strip).to eql 'HAML partial content'
19
19
  end
20
20
  end
21
21
 
22
22
  context 'no partial options given' do
23
23
  it 'renders the default partial' do
24
24
  get :no_options
25
- response.body.strip.should == 'default partial content'
25
+ expect(response.body.strip).to eql 'default partial content'
26
+ end
27
+ end
28
+
29
+ context 'partial with tag option given' do
30
+ it 'renders an empty tag even though the section contains a partial' do
31
+ get :tag_option
32
+ expect(response.body.strip).to eql '<div class="tag_option"></div>'
26
33
  end
27
34
  end
28
35
 
@@ -32,11 +39,11 @@ describe PartialsController do
32
39
  end
33
40
 
34
41
  it 'renders the given partial' do
35
- response.body.should include 'custom partial content'
42
+ expect(response.body).to include 'custom partial content'
36
43
  end
37
44
 
38
45
  it "doesn't render the default partial" do
39
- response.body.should_not include 'default partial content'
46
+ expect(response.body).to_not include 'default partial content'
40
47
  end
41
48
  end
42
49
 
@@ -46,11 +53,11 @@ describe PartialsController do
46
53
  end
47
54
 
48
55
  it "doesn't render the partial tag" do
49
- response.body.strip.should_not include '<div class="disabled">'
56
+ expect(response.body.strip).to_not include '<div class="disabled">'
50
57
  end
51
58
 
52
59
  it "doesn't render the partial" do
53
- response.body.strip.should_not include 'disabled partial content'
60
+ expect(response.body.strip).to_not include 'disabled partial content'
54
61
  end
55
62
  end
56
63
 
@@ -66,14 +73,21 @@ describe PartialsController do
66
73
 
67
74
  it 'renders partials normally' do
68
75
  get :production_mode
69
- response.body.strip.should include 'partial content'
76
+ expect(response.body.strip).to include 'partial content'
70
77
  end
71
78
  end
72
79
 
73
80
  describe 'partial with block' do
74
- it 'allows to render the block inside the partial' do
81
+ it 'renders the block inside the partial' do
75
82
  get :partial_with_block
76
- response.body.strip.should == "partial line 1.\nblock content.\npartial line 2."
83
+ expect(response.body.strip).to match /partial line 1.\n+block content.\n+partial line 2./
84
+ end
85
+ end
86
+
87
+ describe 'partial with custom partial name and block' do
88
+ it 'renders the block inside the custom partial' do
89
+ get :custom_partial_with_block
90
+ expect(response.body.strip).to match /custom partial line 1.\n+\s*block content\n+custom partial line 2./
77
91
  end
78
92
  end
79
93
  end
@@ -12,18 +12,18 @@ describe ScriptAssetsController do
12
12
  end
13
13
 
14
14
  after :each do
15
- response.should be_success
15
+ expect(response).to be_success
16
16
  end
17
17
 
18
18
  describe 'supported script languages' do
19
19
  it 'allows to use JavaScript assets' do
20
20
  get :javascript
21
- response.body.should have_script_tag '/assets/script_assets/javascript/javascript.js'
21
+ expect(response.body).to have_script_tag '/assets/script_assets/javascript/javascript.js'
22
22
  end
23
23
 
24
24
  it 'allows to use CoffeeScript assets' do
25
25
  get :coffeescript
26
- response.body.should have_script_tag '/assets/script_assets/coffeescript/coffeescript.js'
26
+ expect(response.body).to have_script_tag '/assets/script_assets/coffeescript/coffeescript.js'
27
27
  end
28
28
  end
29
29
 
@@ -33,18 +33,18 @@ describe ScriptAssetsController do
33
33
  end
34
34
 
35
35
  it 'includes the given script file into the page' do
36
- response.body.should have_script_tag '/assets/script_assets/custom_script/different_name.js'
36
+ expect(response.body).to have_script_tag '/assets/script_assets/custom_script/different_name.js'
37
37
  end
38
38
 
39
39
  it "doesn't include the default script file into the page" do
40
- response.body.should_not have_script_tag '/assets/script_assets/custom_script/custom_script.js'
40
+ expect(response.body).to_not have_script_tag '/assets/script_assets/custom_script/custom_script.js'
41
41
  end
42
42
  end
43
43
 
44
44
  context 'setting the script configuration option to false' do
45
45
  it "doesn't include any script tag into the page" do
46
46
  get :no_script
47
- response.body.should_not match /<script/
47
+ expect(response.body).to_not match /<script/
48
48
  end
49
49
  end
50
50
 
@@ -59,7 +59,7 @@ describe ScriptAssetsController do
59
59
 
60
60
  it "doesn't render script assets" do
61
61
  get :production_mode
62
- response.should_not have_script_tag '/assets/script_assets/production_mode/production_mode.js'
62
+ expect(response).to_not have_script_tag '/assets/script_assets/production_mode/production_mode.js'
63
63
  end
64
64
  end
65
65
  end
@@ -12,33 +12,33 @@ describe StyleAssetsController do
12
12
  end
13
13
 
14
14
  after :each do
15
- response.should be_success
15
+ expect(response).to be_success
16
16
  end
17
17
 
18
18
  describe 'supported style languages' do
19
19
  it 'CSS assets' do
20
20
  get :css
21
- response.body.should have_style_tag '/assets/style_assets/css/css.css'
21
+ expect(response.body).to have_style_tag '/assets/style_assets/css/css.css'
22
22
  end
23
23
 
24
24
  it 'SASS assets' do
25
25
  get :sass
26
- response.body.should have_style_tag '/assets/style_assets/sass/sass.css'
26
+ expect(response.body).to have_style_tag '/assets/style_assets/sass/sass.css'
27
27
  end
28
28
 
29
29
  it 'CSS.SASS assets' do
30
30
  get :css_sass
31
- response.body.should have_style_tag '/assets/style_assets/css_sass/css_sass.css'
31
+ expect(response.body).to have_style_tag '/assets/style_assets/css_sass/css_sass.css'
32
32
  end
33
33
 
34
34
  it 'SCSS assets' do
35
35
  get :scss
36
- response.body.should have_style_tag '/assets/style_assets/scss/scss.css'
36
+ expect(response.body).to have_style_tag '/assets/style_assets/scss/scss.css'
37
37
  end
38
38
 
39
39
  it 'CSS.SCSS assets' do
40
40
  get :css_scss
41
- response.body.should have_style_tag '/assets/style_assets/css_scss/css_scss.css'
41
+ expect(response.body).to have_style_tag '/assets/style_assets/css_scss/css_scss.css'
42
42
  end
43
43
  end
44
44
 
@@ -48,18 +48,18 @@ describe StyleAssetsController do
48
48
  end
49
49
 
50
50
  it 'includes the given style file into the page' do
51
- response.body.should have_style_tag '/assets/style_assets/custom_style/different_name.css'
51
+ expect(response.body).to have_style_tag '/assets/style_assets/custom_style/different_name.css'
52
52
  end
53
53
 
54
54
  it "doesn't include the default script file into the page" do
55
- response.body.should_not have_style_tag '/assets/style_assets/custom_style/custom_style.css'
55
+ expect(response.body).to_not have_style_tag '/assets/style_assets/custom_style/custom_style.css'
56
56
  end
57
57
  end
58
58
 
59
59
  context 'setting the script configuration option to false' do
60
60
  it "doesn't include any script tag into the page" do
61
61
  get :no_style
62
- response.body.should_not have_style_tag '/assets/style_assets/no_style/no_style.css'
62
+ expect(response.body).to_not have_style_tag '/assets/style_assets/no_style/no_style.css'
63
63
  end
64
64
  end
65
65
 
@@ -75,7 +75,7 @@ describe StyleAssetsController do
75
75
 
76
76
  it "doesn't render style assets" do
77
77
  get :production_mode
78
- response.body.should_not have_style_tag '/assets/style_assets/production_mode/production_mode.css'
78
+ expect(response.body).to_not have_style_tag '/assets/style_assets/production_mode/production_mode.css'
79
79
  end
80
80
  end
81
81
  end
@@ -5,17 +5,17 @@ describe ViewTypesController do
5
5
 
6
6
  describe 'supported view types' do
7
7
  after :each do
8
- response.should be_success
8
+ expect(response).to be_success
9
9
  end
10
10
 
11
11
  it 'allows to use the section helper in ERB views' do
12
12
  get :erb
13
- response.body.strip.should == 'Foo partial content'
13
+ expect(response.body.strip).to eql 'Foo partial content'
14
14
  end
15
15
 
16
16
  it 'allows to use the section helper in HAML views' do
17
17
  get :haml
18
- response.body.strip.should == 'Foo partial content'
18
+ expect(response.body.strip).to eql 'Foo partial content'
19
19
  end
20
20
  end
21
21
  end
@@ -0,0 +1,14 @@
1
+ class ImageAssetsController < ApplicationController
2
+
3
+ def gif
4
+ end
5
+
6
+ def jpg
7
+ end
8
+
9
+ def jpeg
10
+ end
11
+
12
+ def png
13
+ end
14
+ end
@@ -20,4 +20,10 @@ class PartialsController < ApplicationController
20
20
 
21
21
  def partial_with_block
22
22
  end
23
+
24
+ def tag_option
25
+ end
26
+
27
+ def custom_partial_with_block
28
+ end
23
29
  end
@@ -0,0 +1 @@
1
+ <%= image_tag 'image_assets/gif/pic.gif' %>
@@ -0,0 +1 @@
1
+ <%= image_tag 'image_assets/jpeg/pic.jpeg' %>
@@ -0,0 +1 @@
1
+ <%= image_tag 'image_assets/jpg/pic.jpg' %>
@@ -0,0 +1 @@
1
+ <%= image_tag 'image_assets/png/pic.png' %>
@@ -0,0 +1,3 @@
1
+ <%= section 'partials/custom_partial_with_block', partial: 'different_name' do %>
2
+ block content
3
+ <% end %>
@@ -0,0 +1 @@
1
+ <%= section 'partials/tag_option', partial: :tag %>
@@ -3,10 +3,11 @@ require File.expand_path('../boot', __FILE__)
3
3
  require "action_controller/railtie"
4
4
  require "action_view/railtie"
5
5
  require "sprockets/railtie"
6
+ # require 'rails/all'
7
+ require 'haml'
6
8
 
7
- if defined?(Bundler)
8
- Bundler.require(*Rails.groups(:assets => %w(development test)))
9
- end
9
+ Bundler.require(*Rails.groups(:assets => %w(development test)))
10
+ # require 'sections_rails'
10
11
 
11
12
  module Dummy
12
13
  class Application < Rails::Application
@@ -1,7 +1,11 @@
1
1
  require 'rubygems'
2
+ gemfile = File.expand_path('../../../../Gemfile', __FILE__)
2
3
 
3
- # Set up gems listed in the Gemfile.
4
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__)
4
+ if File.exist?(gemfile)
5
+ ENV['BUNDLE_GEMFILE'] = gemfile
6
+ require 'bundler'
7
+ Bundler.setup
8
+ end
5
9
 
6
- require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
10
+ $:.unshift File.expand_path('../../../../lib', __FILE__)
7
11
 
@@ -27,10 +27,7 @@ Dummy::Application.configure do
27
27
  # Tell Action Mailer not to deliver emails to the real world.
28
28
  # The :test delivery method accumulates sent emails in the
29
29
  # ActionMailer::Base.deliveries array.
30
- config.action_mailer.delivery_method = :test
31
-
32
- # Raise exception on mass assignment protection for Active Record models
33
- config.active_record.mass_assignment_sanitizer = :strict
30
+ #config.action_mailer.delivery_method = :test
34
31
 
35
32
  # Print deprecation notices to the stderr
36
33
  config.active_support.deprecation = :stderr
File without changes
File without changes