ballonizer 0.5.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/examples/ballonizer_app/test.db +0 -0
- data/lib/ballonizer.rb +20 -7
- data/spec/ballonizer_spec.rb +74 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 780ce40c1dc740975c9efab98d89424a0b985fc3
|
4
|
+
data.tar.gz: 59e8ef21b8d41b5ecf3967f9d970ff9128980856
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a326072d5470694d5be5130b74adea5ce2099c2b0ccb1c0943bcffcb93b7f8054e6e2b51a878ced816e238d3c5e2dbfab2ecee1f61dbdc3279866ef2b75e180
|
7
|
+
data.tar.gz: c82f1c4356ffe12dcdf2cf8a3ec483f143c8930bab14c9513114a3bd127e497a7df25dc47b360cfe8609d58a0667c2553c0e7d82783e06c78250a7f28d796019
|
Binary file
|
data/lib/ballonizer.rb
CHANGED
@@ -55,6 +55,16 @@ require 'sprockets'
|
|
55
55
|
# ballonized_image_ballons.
|
56
56
|
#
|
57
57
|
# Changelog:
|
58
|
+
# v0.5.1:
|
59
|
+
# * js_load_snippet can take a settings arg too. Fixed ballonize_page to
|
60
|
+
# use the :form_handler_url from the settings argument.
|
61
|
+
# v0.5.0:
|
62
|
+
# * The *_html_links methods can take a settings argument.
|
63
|
+
# * Fixed bug where passing a new asset path to the ballonize_page don't
|
64
|
+
# settings parameter change the asset path that it uses.
|
65
|
+
# * Asset path settings now are parsed as real URIs (need to have a
|
66
|
+
# trailing slash if the intent is use as a dir).
|
67
|
+
# * Updated the rspec version used by the gem (fixed deprecation).
|
58
68
|
# v0.4.0:
|
59
69
|
# * Changed the way the Javascript module add containers in the page
|
60
70
|
# to avoid creating invalid HTML4.0.1/XHTML1.1/HTML5 documents.
|
@@ -403,7 +413,7 @@ class Ballonizer
|
|
403
413
|
# @raise [Ballonizer::Error] If the mime-type don't match either 'text/html'
|
404
414
|
# or 'application/xhtml+xml'.
|
405
415
|
def ballonize_page(page, page_url, mime_type, settings = {})
|
406
|
-
settings =
|
416
|
+
settings = @settings.merge(settings)
|
407
417
|
|
408
418
|
# can raise Ballonizer::Error if the mime-type is invalid
|
409
419
|
parsed_page = Workaround.parse_html_or_xhtml(page, mime_type)
|
@@ -437,7 +447,7 @@ class Ballonizer
|
|
437
447
|
head.children.last.add_next_sibling(js_libs_html_links(settings))
|
438
448
|
end
|
439
449
|
if settings[:add_js_for_edition]
|
440
|
-
head.children.last.add_next_sibling(
|
450
|
+
head.children.last.add_next_sibling(js_load_snippet(settings))
|
441
451
|
end
|
442
452
|
end
|
443
453
|
|
@@ -481,17 +491,20 @@ class Ballonizer
|
|
481
491
|
end
|
482
492
|
|
483
493
|
# Return a String with the snippet added to the pages to allow edition in them.
|
494
|
+
# @param settings [Hash{Symbol => String}] Optional. Hash to be merged with
|
495
|
+
# the instance #settings (this argument override the #settings ones).
|
484
496
|
# @return [String] The added snippet. Already with the <script/> tag around it.
|
485
|
-
def js_load_snippet
|
486
|
-
|
497
|
+
def js_load_snippet(settings = {})
|
498
|
+
settings = @settings.merge(settings)
|
499
|
+
<<-EOF
|
487
500
|
<script type="text/javascript">
|
488
501
|
$(document).ready(function() {
|
489
|
-
Ballonizer('#{
|
502
|
+
Ballonizer('#{settings[:form_handler_url]}',
|
490
503
|
'.ballonizer_image_container',
|
491
504
|
$('body'));
|
492
505
|
})
|
493
506
|
</script>
|
494
|
-
|
507
|
+
EOF
|
495
508
|
end
|
496
509
|
|
497
510
|
# Executes the create_table operations over the Sequel::Database argument.
|
@@ -536,7 +549,7 @@ class Ballonizer
|
|
536
549
|
# @return [String,NilClass] A String when the :css_asset_path_for_link is
|
537
550
|
# defined, nil otherwise.
|
538
551
|
def css_html_links(settings = {})
|
539
|
-
settings =
|
552
|
+
settings = @settings.merge(settings)
|
540
553
|
return nil unless settings[:css_asset_path_for_link]
|
541
554
|
|
542
555
|
link_template = '<link rel="stylesheet" type="text/css" href="PATH" />'
|
data/spec/ballonizer_spec.rb
CHANGED
@@ -4,6 +4,7 @@ require 'rspec-html-matchers'
|
|
4
4
|
require 'equivalent-xml'
|
5
5
|
require 'stringio'
|
6
6
|
require 'rexml/document'
|
7
|
+
require 'nokogiri'
|
7
8
|
|
8
9
|
# make the changes in the BD restricted to the example
|
9
10
|
RSpec.configure do |c|
|
@@ -108,6 +109,7 @@ describe Ballonizer do
|
|
108
109
|
# definitions to be overriden in need, but who doesn't need a *_example
|
109
110
|
# counterpart (are so simple that clone and change isn't pratical)
|
110
111
|
let (:mime_type) { 'application/xhtml+xml' }
|
112
|
+
let (:ballonize_page_settings_arg) { {} }
|
111
113
|
|
112
114
|
# Definitions ending with '_example' are to be cloned and defined in a
|
113
115
|
# context without the sufix. Definitions without the sufix are used in the
|
@@ -163,9 +165,6 @@ describe Ballonizer do
|
|
163
165
|
let (:page_url_example) do
|
164
166
|
'http://comic-translation.com/tr/pt-BR/a_comic/'
|
165
167
|
end
|
166
|
-
let (:settings_example) do
|
167
|
-
{}
|
168
|
-
end
|
169
168
|
let (:submit_json_example) do
|
170
169
|
'{"http://imgs.xkcd.com/comics/cells.png":[{"left":0,"top":0,"width":1,"height":0.23837209302325582,"font_size":15,"text":"When you see a claim that a common drug or vitamin \"kills cancer cells in a petri dish\", keep in mind:"},{"left":0.0963302752293578,"top":0.9273255813953488,"width":0.7798165137614679,"height":0.055232558139534885,"font_size":16,"text":"So does a handgun."}]}'
|
171
170
|
end
|
@@ -180,14 +179,15 @@ describe Ballonizer do
|
|
180
179
|
let (:env) { env_example }
|
181
180
|
let (:original_page) { original_page_example.to_s }
|
182
181
|
let (:page_url) { page_url_example }
|
183
|
-
let (:settings) { settings_example }
|
184
182
|
let (:submit_json) { submit_json_example }
|
185
183
|
let (:submit_hash) { submit_hash_example }
|
186
184
|
|
187
185
|
# Definition who need others (no *_example)
|
188
186
|
let (:instance) { described_class.new(*ballonizer_new_args) }
|
189
187
|
let (:ballonize_page_call) do
|
190
|
-
lambda { instance.ballonize_page(
|
188
|
+
lambda { instance.ballonize_page(
|
189
|
+
original_page, page_url, mime_type, ballonize_page_settings_arg
|
190
|
+
)}
|
191
191
|
end
|
192
192
|
let (:ballonized_page) do
|
193
193
|
ballonize_page_call.call
|
@@ -273,10 +273,24 @@ describe Ballonizer do
|
|
273
273
|
})
|
274
274
|
end
|
275
275
|
|
276
|
-
it do
|
276
|
+
it 'insert the link tag (with the correct path)' do
|
277
277
|
# the example html don't have any link tag, so if there one
|
278
278
|
# it was added by the method
|
279
279
|
should have_tag('link', :with => { type: 'text/css' })
|
280
|
+
# we are using xhtml, so we parse as xml
|
281
|
+
link_href = Nokogiri::XML(subject).at_css('link').attr('href')
|
282
|
+
expect(link_href).to match(/^\/assets\/css\//)
|
283
|
+
end
|
284
|
+
|
285
|
+
context 'but the settings argument override the path' do
|
286
|
+
let (:ballonize_page_settings_arg) do
|
287
|
+
{ css_asset_path_for_link: '/other_assets/css/' }
|
288
|
+
end
|
289
|
+
it 'use the settings argument path' do
|
290
|
+
# we are using xhtml, so we parse as xml
|
291
|
+
link_href = Nokogiri::XML(subject).at_css('link').attr('href')
|
292
|
+
expect(link_href).to match(/^\/other_assets\/css\//)
|
293
|
+
end
|
280
294
|
end
|
281
295
|
end
|
282
296
|
context 'and the settings define to insert js' do
|
@@ -289,8 +303,35 @@ describe Ballonizer do
|
|
289
303
|
})
|
290
304
|
end
|
291
305
|
|
292
|
-
it do
|
306
|
+
it 'insert the script tag (with the correct src)' do
|
293
307
|
should have_tag('script', :with => { type: 'text/javascript' })
|
308
|
+
# we are using xhtml, so we parse as xml
|
309
|
+
script_src = Nokogiri::XML(subject).at_css('script').attr('src')
|
310
|
+
expect(script_src).to match(/^\/assets\/js\//)
|
311
|
+
end
|
312
|
+
|
313
|
+
context 'but the settings argument override the path' do
|
314
|
+
let (:ballonize_page_settings_arg) do
|
315
|
+
{ js_asset_path_for_link: '/other_assets/js/' }
|
316
|
+
end
|
317
|
+
it 'use the settings argument path' do
|
318
|
+
# we are using xhtml, so we parse as xml
|
319
|
+
script_src = Nokogiri::XML(subject).at_css('script').attr('src')
|
320
|
+
expect(script_src).to match(/^\/other_assets\/js\//)
|
321
|
+
end
|
322
|
+
end
|
323
|
+
end
|
324
|
+
context 'and the settings argument override the form_handler_url' do
|
325
|
+
let (:ballonize_page_settings_arg) do
|
326
|
+
{ form_handler_url: '/other_request_handler',
|
327
|
+
add_js_for_edition: true,
|
328
|
+
add_required_js_libs_for_edition: false
|
329
|
+
}
|
330
|
+
end
|
331
|
+
it 'change the js snippet to use the argument one' do
|
332
|
+
# we are using xhtml, so we parse as xml
|
333
|
+
script_text = Nokogiri::XML(subject).at_css('script').text
|
334
|
+
expect(script_text).to match(/\/other_request_handler/)
|
294
335
|
end
|
295
336
|
end
|
296
337
|
end
|
@@ -652,7 +693,32 @@ describe Ballonizer do
|
|
652
693
|
end
|
653
694
|
end
|
654
695
|
|
655
|
-
|
696
|
+
describe '#js_load_snippet' do
|
697
|
+
subject { instance.js_load_snippet(settings_arg) }
|
698
|
+
|
699
|
+
let (:settings_arg) { Hash.new }
|
700
|
+
let (:ballonizer_settings) do
|
701
|
+
ballonizer_settings_example.merge({
|
702
|
+
form_handler_url: '/request_handler'
|
703
|
+
})
|
704
|
+
end
|
705
|
+
|
706
|
+
it 'return contains the :form_handler_url setting' do
|
707
|
+
should match(instance.settings[:form_handler_url])
|
708
|
+
end
|
709
|
+
|
710
|
+
context 'when the settings argument is passed' do
|
711
|
+
let (:settings_arg) do
|
712
|
+
{ form_handler_url: '/other_request_handler' }
|
713
|
+
end
|
714
|
+
|
715
|
+
it 'use the argument one' do
|
716
|
+
should match(settings_arg[:form_handler_url])
|
717
|
+
should_not match(instance.settings[:form_handler_url])
|
718
|
+
end
|
719
|
+
end
|
720
|
+
end
|
721
|
+
|
656
722
|
describe '#css_html_links' do
|
657
723
|
shared_examples 'using settings parameter' do
|
658
724
|
context 'and a path is passed by the settings hash argument' do
|
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.5.
|
4
|
+
version: 0.5.1
|
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-
|
11
|
+
date: 2013-07-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|