ballonizer 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5bf4f7c8da8c6850ded2132c67beebc4bb5306ff
4
- data.tar.gz: 8238aea52c3812bdb5ef6113744d2c2f01d0e488
3
+ metadata.gz: 8b70575ef73f0f6eb75c78152bc2528cf5b265f8
4
+ data.tar.gz: ee3aca3f015051952cf27d02f566ba82db4d9202
5
5
  SHA512:
6
- metadata.gz: b7b614154da4bf1e78483c9266e067d33a425f57dd4d10f662732163316a5852b76aac86e59aba5e591ac9531d45d1829b1990b9e3b6d349d2f6ee2693b8d527
7
- data.tar.gz: 4ebfcf50deafb861e2cce5f5e20120399e133748ece9865dec01c1def8cf936ff81b926d6e4f1fbca8aca39c8ff6754507a9743c2d1074813a7ef5e1150d31b8
6
+ metadata.gz: 3e2c3f7d30a6e276d71cbb2cbd3b024e537fb0cd1701afa191a240bbab4d74d7a474ced17b23a5d2a8ebf2cce38939b9787ce1455eaecd6a695dd4be50a03209
7
+ data.tar.gz: 4314720810323104e83f0cc6b9c9049966b75de5df711126aead63092900a3d9e3824b8ab2b85794898e106e964340f21ef94daeebf581add700087b00d29a1f
@@ -17,9 +17,9 @@ ballonizer = Ballonizer.new(db_uri, {
17
17
  create_tables_if_none: true,
18
18
  form_handler_url: '/request_handler',
19
19
  add_required_css: true,
20
- css_asset_path_for_link: '/assets',
20
+ css_asset_path_for_link: '/assets/',
21
21
  add_required_js_libs_for_edition: true,
22
- js_asset_path_for_link: '/assets'
22
+ js_asset_path_for_link: '/assets/'
23
23
  })
24
24
 
25
25
  app = Rack::Builder.new do
data/lib/ballonizer.rb CHANGED
@@ -84,7 +84,6 @@ class Ballonizer
84
84
  # @api private Don't use the methods of this module. They are for internal use only.
85
85
  module Workaround
86
86
  def self.join_uris(base, relative)
87
- base = base.end_with?('/') ? base : base + '/'
88
87
  Addressable::URI.parse(base).join(relative).to_s
89
88
  end
90
89
 
@@ -395,8 +394,8 @@ class Ballonizer
395
394
  # @param page [String] The (X)HTML page.
396
395
  # @param page_url [String] The url of the page to be ballonized, necessary
397
396
  # to make absolute the src attribute of img (if it's relative).
398
- # @param settings [Hash{Symbol => String}] Optional. If not provided the
399
- # #settings will be used.
397
+ # @param settings [Hash{Symbol => String}] Optional. Hash to be merged with
398
+ # the instance #settings (this argument override the #settings ones).
400
399
  # @param mime_type A string that have the substring 'text/html' or
401
400
  # 'application/xhtml+xml'.
402
401
  # @return [String] The ballonized page (new string), or the same string,
@@ -432,10 +431,10 @@ class Ballonizer
432
431
 
433
432
  head = parsed_page.at_css('head')
434
433
  if settings[:add_required_css]
435
- head.children.last.add_next_sibling(self.css_html_links)
434
+ head.children.last.add_next_sibling(css_html_links(settings))
436
435
  end
437
436
  if settings[:add_required_js_libs_for_edition]
438
- head.children.last.add_next_sibling(self.js_libs_html_links)
437
+ head.children.last.add_next_sibling(js_libs_html_links(settings))
439
438
  end
440
439
  if settings[:add_js_for_edition]
441
440
  head.children.last.add_next_sibling(self.js_load_snippet)
@@ -531,12 +530,14 @@ class Ballonizer
531
530
 
532
531
  # The (X)HTML fragment with the link tags that are added to the page by
533
532
  # ballonize_page if the :add_required_css setting is true (the default
534
- # is false). If the :css_asset_path_for_link isn't set (what is the
535
- # default) this method return nil.
536
- # @return [String,NilClass] A frozen string.
537
- def css_html_links
533
+ # is false).
534
+ # @param settings [Hash{Symbol => String}] Optional. Hash to be merged with
535
+ # the instance #settings (this argument override the #settings ones).
536
+ # @return [String,NilClass] A String when the :css_asset_path_for_link is
537
+ # defined, nil otherwise.
538
+ def css_html_links(settings = {})
539
+ settings = self.settings.merge(settings)
538
540
  return nil unless settings[:css_asset_path_for_link]
539
- return @css_html_links if @css_html_links
540
541
 
541
542
  link_template = '<link rel="stylesheet" type="text/css" href="PATH" />'
542
543
  css_paths = self.class.asset_logical_paths.select do | p |
@@ -548,17 +549,19 @@ class Ballonizer
548
549
  link_template.sub('PATH', p)
549
550
  end
550
551
 
551
- @css_html_links = links.join('').freeze
552
+ links.join('')
552
553
  end
553
554
 
554
555
  # The (X)HTML fragment with the script tags that are added to the page by
555
556
  # ballonize_page if the :add_required_js_libs_for_edition setting is true
556
- # (the default is false). If the :js_asset_path_for_link isn't set (what
557
- # is the default) this method return nil.
558
- # @return [String,NilClass] A frozen string.
559
- def js_libs_html_links
557
+ # (the default is false).
558
+ # @param settings [Hash{Symbol => String}] Optional. Hash to be merged with
559
+ # the instance #settings (this argument override the #settings ones).
560
+ # @return [String,NilClass] A String when the :js_asset_path_for_link is
561
+ # defined, nil otherwise.
562
+ def js_libs_html_links(settings = {})
563
+ settings = self.settings.merge(settings)
560
564
  return nil unless settings[:js_asset_path_for_link]
561
- return @js_libs_html_links if @js_libs_html_links
562
565
 
563
566
  link_template = '<script type="text/javascript" src="PATH" ></script>'
564
567
  js_libs_paths = self.class.asset_logical_paths.select do | p |
@@ -570,7 +573,7 @@ class Ballonizer
570
573
  link_template.sub('PATH', p)
571
574
  end
572
575
 
573
- @js_libs_html_links = links.join('').freeze
576
+ links.join('')
574
577
  end
575
578
 
576
579
  # List of paths (relative to the gem root directory) to the directories with
@@ -269,7 +269,7 @@ describe Ballonizer do
269
269
  let (:ballonizer_settings) do
270
270
  ballonizer_settings_example.merge({
271
271
  add_required_css: true,
272
- css_asset_path_for_link: 'assets/css'
272
+ css_asset_path_for_link: '/assets/css/'
273
273
  })
274
274
  end
275
275
 
@@ -285,7 +285,7 @@ describe Ballonizer do
285
285
  # this option is added to avoid a false positive in the test
286
286
  add_js_for_edition: false,
287
287
  add_required_js_libs_for_edition: true,
288
- js_asset_path_for_link: 'assets/js'
288
+ js_asset_path_for_link: '/assets/js/'
289
289
  })
290
290
  end
291
291
 
@@ -530,7 +530,7 @@ describe Ballonizer do
530
530
  lambda { instance.valid_submit_hash?(submit_hash, true) }
531
531
  end
532
532
 
533
- it { expect(method_call).to_not raise_error(described_class::SubmitError) }
533
+ it { expect(method_call).to_not raise_error }
534
534
  it { expect(method_call.call).to be_true }
535
535
  end
536
536
  end
@@ -652,47 +652,87 @@ describe Ballonizer do
652
652
  end
653
653
  end
654
654
 
655
+ # to be used with #css_html_links and #js_libs_html_links
655
656
  describe '#css_html_links' do
657
+ shared_examples 'using settings parameter' do
658
+ context 'and a path is passed by the settings hash argument' do
659
+ it 'use the path from the argument' do
660
+ css_links = instance.css_html_links({
661
+ css_asset_path_for_link: '/other_assets/css/'
662
+ })
663
+
664
+ REXML::Document.new("<root>#{css_links}</root>")
665
+ .root.children.each do | e |
666
+ expect(e.attributes['href']).to match(/^\/other_assets\/css\//)
667
+ end
668
+ end
669
+ end
670
+ end
671
+
656
672
  context "when the path for the css isn't configured" do
657
673
  it 'returns nil' do
658
674
  expect(instance.css_html_links).to eq nil
659
675
  end
676
+
677
+ include_examples 'using settings parameter'
660
678
  end
661
679
  context 'when the path for the css is configured' do
662
680
  let (:ballonizer_settings) do
663
681
  ballonizer_settings_example.merge({
664
- css_asset_path_for_link: 'assets/css'
682
+ css_asset_path_for_link: '/assets/css/'
665
683
  })
666
684
  end
667
685
 
668
686
  it 'return a HTML string with links prefixed by the path' do
669
687
  REXML::Document.new("<root>#{instance.css_html_links}</root>")
670
688
  .root.children.each do | e |
671
- expect(e.attributes['href']).to match(/^assets\/css/)
689
+ expect(e.attributes['href']).to match(/^\/assets\/css\//)
672
690
  end
673
691
  end
692
+
693
+ include_examples 'using settings parameter'
674
694
  end
675
695
  end
676
696
 
677
697
  describe '#js_libs_html_links' do
698
+ shared_examples 'using settings parameter' do
699
+ context 'and a path is passed by the settings hash argument' do
700
+ it 'use the path from the argument' do
701
+ js_scripts = instance.js_libs_html_links({
702
+ js_asset_path_for_link: '/other_assets/js/'
703
+ })
704
+
705
+ REXML::Document.new("<root>#{js_scripts}</root>")
706
+ .root.children.each do | e |
707
+ expect(e.attributes['src']).to match(/^\/other_assets\/js\//)
708
+ end
709
+ end
710
+ end
711
+ end
712
+
678
713
  context "when the path for the js libs isn't configured" do
679
714
  it 'returns nil' do
680
715
  expect(instance.js_libs_html_links).to eq nil
681
716
  end
717
+
718
+ include_examples 'using settings parameter'
682
719
  end
720
+
683
721
  context 'when the path for the js libs is configured' do
684
722
  let (:ballonizer_settings) do
685
723
  ballonizer_settings_example.merge({
686
- js_asset_path_for_link: 'assets/js'
724
+ js_asset_path_for_link: '/assets/js/'
687
725
  })
688
726
  end
689
727
 
690
728
  it 'return a HTML string with links prefixed by the path' do
691
729
  REXML::Document.new("<root>#{instance.js_libs_html_links}</root>")
692
730
  .root.children.each do | e |
693
- expect(e.attributes['src']).to match(/^assets\/js/)
731
+ expect(e.attributes['src']).to match(/^\/assets\/js\//)
694
732
  end
695
733
  end
734
+
735
+ include_examples 'using settings parameter'
696
736
  end
697
737
  end
698
738
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ballonizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henrique Becker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-16 00:00:00.000000000 Z
11
+ date: 2013-07-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -151,33 +151,19 @@ dependencies:
151
151
  - !ruby/object:Gem::Version
152
152
  version: 0.8.4
153
153
  - !ruby/object:Gem::Dependency
154
- name: rspec-core
154
+ name: rspec
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
157
  - - ~>
158
158
  - !ruby/object:Gem::Version
159
- version: '2.13'
159
+ version: '2.14'
160
160
  type: :development
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
164
  - - ~>
165
165
  - !ruby/object:Gem::Version
166
- version: '2.13'
167
- - !ruby/object:Gem::Dependency
168
- name: rspec-expectations
169
- requirement: !ruby/object:Gem::Requirement
170
- requirements:
171
- - - ~>
172
- - !ruby/object:Gem::Version
173
- version: '2.13'
174
- type: :development
175
- prerelease: false
176
- version_requirements: !ruby/object:Gem::Requirement
177
- requirements:
178
- - - ~>
179
- - !ruby/object:Gem::Version
180
- version: '2.13'
166
+ version: '2.14'
181
167
  - !ruby/object:Gem::Dependency
182
168
  name: rspec-html-matchers
183
169
  requirement: !ruby/object:Gem::Requirement