dragonfly_svg 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +2 -2
  4. data/README.md +9 -1
  5. data/lib/dragonfly_svg.rb +3 -7
  6. data/lib/dragonfly_svg/analysers/aspect_ratio_analyser.rb +17 -0
  7. data/lib/dragonfly_svg/analysers/base.rb +11 -0
  8. data/lib/dragonfly_svg/analysers/height_analyser.rb +16 -0
  9. data/lib/dragonfly_svg/analysers/landscape_analyser.rb +17 -0
  10. data/lib/dragonfly_svg/analysers/portrait_analyser.rb +17 -0
  11. data/lib/dragonfly_svg/analysers/svg_properties.rb +4 -6
  12. data/lib/dragonfly_svg/analysers/width_analyser.rb +16 -0
  13. data/lib/dragonfly_svg/plugin.rb +16 -20
  14. data/lib/dragonfly_svg/processors/extend_ids.rb +4 -6
  15. data/lib/dragonfly_svg/processors/remove_namespaces.rb +2 -3
  16. data/lib/dragonfly_svg/processors/set_attribute.rb +1 -3
  17. data/lib/dragonfly_svg/processors/set_dimensions.rb +4 -12
  18. data/lib/dragonfly_svg/processors/set_namespace.rb +2 -4
  19. data/lib/dragonfly_svg/processors/set_preserve_aspect_ratio.rb +3 -11
  20. data/lib/dragonfly_svg/processors/set_view_box.rb +3 -12
  21. data/lib/dragonfly_svg/version.rb +1 -1
  22. data/samples/sample.png +0 -0
  23. data/test/dragonfly_svg/analysers/svg_properties_test.rb +1 -3
  24. data/test/dragonfly_svg/plugin_test.rb +42 -3
  25. data/test/dragonfly_svg/processors/extend_ids_test.rb +1 -3
  26. data/test/dragonfly_svg/processors/remove_namespaces_test.rb +1 -3
  27. data/test/dragonfly_svg/processors/set_attribute_test.rb +3 -5
  28. data/test/dragonfly_svg/processors/set_dimensions_test.rb +1 -3
  29. data/test/dragonfly_svg/processors/set_namespace_test.rb +1 -3
  30. data/test/dragonfly_svg/processors/set_preserve_aspect_ratio_test.rb +4 -6
  31. data/test/dragonfly_svg/processors/set_view_box_test.rb +1 -3
  32. data/test/test_helper.rb +3 -3
  33. metadata +9 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 535a838609a37371bc692cd6a18581fb6ee4e7be
4
- data.tar.gz: 00c687d365a5b7600ec2ad7a3f0ebc28750e5511
3
+ metadata.gz: 0a80f5be599ee36aeef6e1fb8b3ac547eacfa5dd
4
+ data.tar.gz: 3381778fb2df92c6c806404a39f8e873aee38193
5
5
  SHA512:
6
- metadata.gz: f313203428612c6bd4a44a47912bfcf236703939124f1305126242e7597729dff33e5e87ca6daf30f2c03903fb2dc99fe738737a099b4dd8b4ca88b9e2a5bd81
7
- data.tar.gz: 84dad19fc19dbb7a62af87c4457eb0b91d44b35a86492222b9d2bac48bbfe72b36acea8753830c32a995a33bce75712bd6726f9b77beb0f9f968c9bb7a7c7284
6
+ metadata.gz: daa3efc319ebe8457c22f460f1cf69e00c6bd8b9f270d98983d7d5d927b6d36c12dedf183ffe8f7d93c98014880bd0a795b7694ba98291a0c55a8ba1b48648fb
7
+ data.tar.gz: bb23dfbe0b3f524e276962fe851bb95a8712fb442c7164df77d761d6baac63b7bf39af1595804a239cc2c14ac4422d94ecfe366eaca0f5d0c2e8c9d8d8afbbcb
data/.gitignore CHANGED
@@ -20,3 +20,4 @@ tmp
20
20
  *.o
21
21
  *.a
22
22
  mkmf.log
23
+ dragonfly.log
data/.travis.yml CHANGED
@@ -2,11 +2,11 @@ language: ruby
2
2
  cache: bundler
3
3
  script: 'bundle exec rake'
4
4
  rvm:
5
- - 1.9.3
5
+ - 2.2.2
6
6
 
7
7
  notifications:
8
8
  email:
9
9
  recipients:
10
10
  - tomas.celizna@gmail.com
11
11
  on_failure: change
12
- on_success: never
12
+ on_success: never
data/README.md CHANGED
@@ -60,6 +60,14 @@ Removes the `xmlns` namespace from the SVG.
60
60
  svg.remove_namespaces
61
61
  ```
62
62
 
63
+ ### SetAttribute
64
+
65
+ Allows to set attribute for specified `xpath`:
66
+
67
+ ```ruby
68
+ svg.set_attribute('./*[name()="svg"]', 'style', 'margin: 50px;')
69
+ ```
70
+
63
71
  ### SetDimensions
64
72
 
65
73
  Sets the dimensions of the SVG. Takes two parameters: `width` and `height`
@@ -100,4 +108,4 @@ svg.set_viewbox(0, 0, 400, 600) # viewBox="0 0 400 600"
100
108
  2. Create your feature branch (`git checkout -b my-new-feature`)
101
109
  3. Commit your changes (`git commit -am 'Add some feature'`)
102
110
  4. Push to the branch (`git push origin my-new-feature`)
103
- 5. Create a new Pull Request
111
+ 5. Create a new Pull Request
data/lib/dragonfly_svg.rb CHANGED
@@ -1,7 +1,3 @@
1
- require "dragonfly"
2
- require "dragonfly_svg/plugin"
3
- require "dragonfly_svg/version"
4
-
5
- Dragonfly.app.configure do
6
- plugin :svg
7
- end
1
+ require 'dragonfly'
2
+ require 'dragonfly_svg/plugin'
3
+ require 'dragonfly_svg/version'
@@ -0,0 +1,17 @@
1
+ module DragonflySvg
2
+ module Analysers
3
+ class AspectRatioAnalyser < Base
4
+ def initialize(app)
5
+ original = app.analysers.items[:aspect_ratio]
6
+ app.add_analyser(:aspect_ratio) do |content|
7
+ if is_svg?(content)
8
+ attrs = content.analyse(:svg_properties)
9
+ attrs[:width].to_f / attrs[:height]
10
+ elsif original
11
+ original.call(content)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,11 @@
1
+ module DragonflySvg
2
+ SVG_MIME_TYPE = 'image/svg+xml'.freeze
3
+
4
+ module Analysers
5
+ class Base
6
+ def is_svg?(content)
7
+ content.mime_type == DragonflySvg::SVG_MIME_TYPE
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,16 @@
1
+ module DragonflySvg
2
+ module Analysers
3
+ class HeightAnalyser < Base
4
+ def initialize(app)
5
+ original = app.analysers.items[:height]
6
+ app.add_analyser(:height) do |content|
7
+ if is_svg?(content)
8
+ content.analyse(:svg_properties)[:height]
9
+ elsif original
10
+ original.call(content)
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,17 @@
1
+ module DragonflySvg
2
+ module Analysers
3
+ class LandscapeAnalyser < Base
4
+ def initialize(app)
5
+ original = app.analysers.items[:landscape]
6
+ app.add_analyser(:landscape) do |content|
7
+ if is_svg?(content)
8
+ attrs = content.analyse(:svg_properties)
9
+ attrs[:width] >= attrs[:height]
10
+ elsif original
11
+ original.call(content)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module DragonflySvg
2
+ module Analysers
3
+ class PortraitAnalyser < Base
4
+ def initialize(app)
5
+ original = app.analysers.items[:portrait]
6
+ app.add_analyser(:portrait) do |content|
7
+ if is_svg?(content)
8
+ attrs = content.analyse(:svg_properties)
9
+ attrs[:width] <= attrs[:height]
10
+ elsif original
11
+ original.call(content)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -3,24 +3,22 @@ require 'nokogiri'
3
3
  module DragonflySvg
4
4
  module Analysers
5
5
  class SvgProperties
6
-
7
- def call content
6
+ def call(content)
8
7
  node = svg_node(content)
9
8
 
10
9
  {
11
10
  width: node.get_attribute('width').to_f,
12
11
  height: node.get_attribute('height').to_f,
13
- id: node.get_attribute('id'),
12
+ id: node.get_attribute('id')
14
13
  }
15
14
  end
16
15
 
17
16
  private # =============================================================
18
17
 
19
- def svg_node content
18
+ def svg_node(content)
20
19
  return unless doc = Nokogiri::XML(content.data)
21
20
  doc.xpath("//*[name()='svg']").first
22
21
  end
23
-
24
22
  end
25
23
  end
26
- end
24
+ end
@@ -0,0 +1,16 @@
1
+ module DragonflySvg
2
+ module Analysers
3
+ class WidthAnalyser < Base
4
+ def initialize(app)
5
+ original = app.analysers.items[:width]
6
+ app.add_analyser(:width) do |content|
7
+ if is_svg?(content)
8
+ content.analyse(:svg_properties)[:width]
9
+ elsif original
10
+ original.call(content)
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -1,4 +1,12 @@
1
+ require 'dragonfly_svg/analysers/base'
2
+
3
+ require 'dragonfly_svg/analysers/aspect_ratio_analyser'
4
+ require 'dragonfly_svg/analysers/height_analyser'
5
+ require 'dragonfly_svg/analysers/landscape_analyser'
6
+ require 'dragonfly_svg/analysers/portrait_analyser'
1
7
  require 'dragonfly_svg/analysers/svg_properties'
8
+ require 'dragonfly_svg/analysers/width_analyser'
9
+
2
10
  require 'dragonfly_svg/processors/extend_ids'
3
11
  require 'dragonfly_svg/processors/remove_namespaces'
4
12
  require 'dragonfly_svg/processors/set_attribute'
@@ -9,26 +17,15 @@ require 'dragonfly_svg/processors/set_view_box'
9
17
 
10
18
  module DragonflySvg
11
19
  class Plugin
12
-
13
- def call app, opts={}
20
+ def call(app, _opts = {})
14
21
  app.add_analyser :svg_properties, DragonflySvg::Analysers::SvgProperties.new
15
- app.add_analyser :width do |content|
16
- content.analyse(:svg_properties)[:width]
17
- end
18
- app.add_analyser :height do |content|
19
- content.analyse(:svg_properties)[:height]
20
- end
21
- app.add_analyser :aspect_ratio do |content|
22
- attrs = content.analyse(:svg_properties)
23
- attrs[:width].to_f / attrs[:height].to_f
24
- end
25
- app.add_analyser :portrait do |content|
26
- attrs = content.analyse(:svg_properties)
27
- attrs[:width] <= attrs[:height]
28
- end
29
- app.add_analyser :landscape do |content|
30
- !content.analyse(:portrait)
31
- end
22
+
23
+ DragonflySvg::Analysers::WidthAnalyser.new(app)
24
+ DragonflySvg::Analysers::HeightAnalyser.new(app)
25
+ DragonflySvg::Analysers::AspectRatioAnalyser.new(app)
26
+ DragonflySvg::Analysers::PortraitAnalyser.new(app)
27
+ DragonflySvg::Analysers::LandscapeAnalyser.new(app)
28
+
32
29
  app.add_analyser :id do |content|
33
30
  content.analyse(:svg_properties)[:id]
34
31
  end
@@ -45,7 +42,6 @@ module DragonflySvg
45
42
  app.add_processor :set_preserve_aspect_ratio, DragonflySvg::Processors::SetPreserveAspectRatio.new
46
43
  app.add_processor :set_view_box, DragonflySvg::Processors::SetViewBox.new
47
44
  end
48
-
49
45
  end
50
46
  end
51
47
 
@@ -3,25 +3,23 @@ require 'nokogiri'
3
3
  module DragonflySvg
4
4
  module Processors
5
5
  class ExtendIds
6
-
7
- def call content, append_str=SecureRandom.urlsafe_base64(8)
6
+ def call(content, append_str = SecureRandom.urlsafe_base64(8))
8
7
  doc = Nokogiri::XML(content.data)
9
8
 
10
9
  # nodes with id attributes
11
- doc.xpath("//*[@id]").each do |node|
10
+ doc.xpath('//*[@id]').each do |node|
12
11
  node_id = node.get_attribute 'id'
13
12
  node.set_attribute 'id', [node_id, append_str].join('-')
14
13
  end
15
14
 
16
15
  # nodes with id references
17
- doc.xpath("//*[@href]").each do |node|
16
+ doc.xpath('//*[@href]').each do |node|
18
17
  node_href = node.get_attribute 'href'
19
18
  node.set_attribute 'href', [node_href, append_str].join('-')
20
19
  end
21
20
 
22
21
  content.update(doc.to_xml)
23
22
  end
24
-
25
23
  end
26
24
  end
27
- end
25
+ end
@@ -3,8 +3,7 @@ require 'nokogiri'
3
3
  module DragonflySvg
4
4
  module Processors
5
5
  class RemoveNamespaces
6
-
7
- def call content
6
+ def call(content)
8
7
  doc = Nokogiri::XML(content.data)
9
8
 
10
9
  doc.remove_namespaces!
@@ -13,4 +12,4 @@ module DragonflySvg
13
12
  end
14
13
  end
15
14
  end
16
- end
15
+ end
@@ -3,8 +3,7 @@ require 'nokogiri'
3
3
  module DragonflySvg
4
4
  module Processors
5
5
  class SetAttribute
6
-
7
- def call content, xpath, attribute_name, value
6
+ def call(content, xpath, attribute_name, value)
8
7
  doc = Nokogiri::XML(content.data)
9
8
 
10
9
  doc.xpath(xpath).each do |node|
@@ -13,7 +12,6 @@ module DragonflySvg
13
12
 
14
13
  content.update(doc.to_xml)
15
14
  end
16
-
17
15
  end
18
16
  end
19
17
  end
@@ -3,18 +3,10 @@ require 'nokogiri'
3
3
  module DragonflySvg
4
4
  module Processors
5
5
  class SetDimensions
6
-
7
- def call content, width, height
8
- doc = Nokogiri::XML(content.data)
9
-
10
- if svg_node = doc.xpath("//*[name()='svg']").first
11
- svg_node.set_attribute 'width', width unless width.nil?
12
- svg_node.set_attribute 'height', height unless height.nil?
13
- end
14
-
15
- content.update(doc.to_xml)
6
+ def call(content, width, height)
7
+ SetAttribute.new.call(content, "//*[name()='svg']", 'width', width) if width
8
+ SetAttribute.new.call(content, "//*[name()='svg']", 'height', height) if height
16
9
  end
17
-
18
10
  end
19
11
  end
20
- end
12
+ end
@@ -3,8 +3,7 @@ require 'nokogiri'
3
3
  module DragonflySvg
4
4
  module Processors
5
5
  class SetNamespace
6
-
7
- def call content, namespace="http://www.w3.org/2000/svg"
6
+ def call(content, namespace = 'http://www.w3.org/2000/svg')
8
7
  doc = Nokogiri::XML(content.data)
9
8
 
10
9
  if svg_node = doc.xpath("//*[name()='svg']").first
@@ -16,7 +15,6 @@ module DragonflySvg
16
15
 
17
16
  content.update(doc.to_xml)
18
17
  end
19
-
20
18
  end
21
19
  end
22
- end
20
+ end
@@ -3,17 +3,9 @@ require 'nokogiri'
3
3
  module DragonflySvg
4
4
  module Processors
5
5
  class SetPreserveAspectRatio
6
-
7
- def call content, value='xMinYMin meet'
8
- doc = Nokogiri::XML(content.data)
9
-
10
- if svg_node = doc.xpath("//*[name()='svg']").first
11
- svg_node.set_attribute 'preserveAspectRatio', value
12
- end
13
-
14
- content.update(doc.to_xml)
6
+ def call(content, value = 'xMinYMin meet')
7
+ SetAttribute.new.call(content, "//*[name()='svg']", 'preserveAspectRatio', value)
15
8
  end
16
-
17
9
  end
18
10
  end
19
- end
11
+ end
@@ -3,19 +3,10 @@ require 'nokogiri'
3
3
  module DragonflySvg
4
4
  module Processors
5
5
  class SetViewBox
6
-
7
- def call content, min_x, min_y, width, height
8
- doc = Nokogiri::XML(content.data)
9
-
6
+ def call(content, min_x, min_y, width, height)
10
7
  value = [min_x, min_y, width, height].map(&:to_s).join(' ')
11
-
12
- if svg_node = doc.xpath("//*[name()='svg']").first
13
- svg_node.set_attribute 'viewBox', value
14
- end
15
-
16
- content.update(doc.to_xml)
8
+ SetAttribute.new.call(content, "//*[name()='svg']", 'viewBox', value)
17
9
  end
18
-
19
10
  end
20
11
  end
21
- end
12
+ end
@@ -1,3 +1,3 @@
1
1
  module DragonflySvg
2
- VERSION = "0.0.3"
2
+ VERSION = '0.0.4'.freeze
3
3
  end
Binary file
@@ -3,7 +3,6 @@ require 'test_helper'
3
3
  module DragonflySvg
4
4
  module Analysers
5
5
  describe SvgProperties do
6
-
7
6
  let(:app) { test_app.configure_with(:svg) }
8
7
  let(:analyser) { DragonflySvg::Analysers::SvgProperties.new }
9
8
  let(:svg) { app.fetch_file(SAMPLES_DIR.join('sample.svg')) }
@@ -28,7 +27,6 @@ module DragonflySvg
28
27
  svg_properties[:id].must_equal 'sample_id'
29
28
  end
30
29
  end
31
-
32
30
  end
33
31
  end
34
- end
32
+ end
@@ -2,7 +2,6 @@ require 'test_helper'
2
2
 
3
3
  module DragonflySvg
4
4
  describe Plugin do
5
-
6
5
  let(:app) { test_app.configure_with(:svg) }
7
6
  let(:svg) { app.fetch_file(SAMPLES_DIR.join('sample.svg')) }
8
7
 
@@ -15,19 +14,60 @@ module DragonflySvg
15
14
 
16
15
  it 'adds #width' do
17
16
  svg.must_respond_to :width
17
+ svg.width.must_equal 200.0
18
18
  end
19
19
 
20
20
  it 'adds #height' do
21
21
  svg.must_respond_to :height
22
+ svg.height.must_equal 300.0
22
23
  end
23
24
 
24
25
  it 'adds #aspect_ratio' do
25
26
  svg.must_respond_to :aspect_ratio
27
+ svg.aspect_ratio.must_equal 0.6666666666666666
28
+ end
29
+
30
+ it 'adds #portrait' do
31
+ svg.must_respond_to :portrait
32
+ svg.portrait.must_equal true
33
+ end
34
+
35
+ it 'adds #landscape' do
36
+ svg.must_respond_to :landscape
37
+ svg.landscape.must_equal false
26
38
  end
27
39
 
28
40
  it 'adds #id' do
29
41
  svg.must_respond_to :id
30
42
  end
43
+
44
+ describe "when handling non svg files" do
45
+ let(:png) { app.fetch_file(SAMPLES_DIR.join('sample.png')) }
46
+
47
+ before do
48
+ test_app.configure_with(:image_magick)
49
+ end
50
+
51
+ it 'still works to get the width' do
52
+ png.width.must_equal 1
53
+ end
54
+
55
+ it 'still works to get the height' do
56
+ png.height.must_equal 1
57
+ end
58
+
59
+ it 'still works to get the aspect ratio' do
60
+ png.aspect_ratio.must_equal 1.0
61
+ end
62
+
63
+ it 'still works to ask for portrait' do
64
+ png.portrait.must_equal true
65
+ end
66
+
67
+ it 'still works to ask for landscape' do
68
+ png.landscape.must_equal false
69
+ end
70
+ end
31
71
  end
32
72
 
33
73
  # ---------------------------------------------------------------------
@@ -57,6 +97,5 @@ module DragonflySvg
57
97
  svg.must_respond_to :set_view_box
58
98
  end
59
99
  end
60
-
61
100
  end
62
- end
101
+ end
@@ -3,7 +3,6 @@ require 'test_helper'
3
3
  module DragonflySvg
4
4
  module Processors
5
5
  describe ExtendIds do
6
-
7
6
  let(:app) { test_app.configure_with(:svg) }
8
7
  let(:processor) { DragonflySvg::Processors::ExtendIds.new }
9
8
  let(:analyser) { DragonflySvg::Analysers::SvgProperties.new }
@@ -22,7 +21,6 @@ module DragonflySvg
22
21
  processor.call(svg, 'foo')
23
22
  analyser.call(svg)[:id].must_equal "#{@orig_id}-foo"
24
23
  end
25
-
26
24
  end
27
25
  end
28
- end
26
+ end
@@ -3,7 +3,6 @@ require 'test_helper'
3
3
  module DragonflySvg
4
4
  module Processors
5
5
  describe RemoveNamespaces do
6
-
7
6
  let(:app) { test_app.configure_with(:svg) }
8
7
  let(:processor) { DragonflySvg::Processors::RemoveNamespaces.new }
9
8
  let(:svg) { Dragonfly::Content.new(app, SAMPLES_DIR.join('sample.svg')) }
@@ -12,7 +11,6 @@ module DragonflySvg
12
11
  processor.call(svg)
13
12
  svg.data.wont_include 'xmlns='
14
13
  end
15
-
16
14
  end
17
15
  end
18
- end
16
+ end
@@ -3,7 +3,6 @@ require 'test_helper'
3
3
  module DragonflySvg
4
4
  module Processors
5
5
  describe SetAttribute do
6
-
7
6
  let(:app) { test_app.configure_with(:svg) }
8
7
  let(:processor) { DragonflySvg::Processors::SetAttribute.new }
9
8
  let(:analyser) { DragonflySvg::Analysers::SvgProperties.new }
@@ -11,17 +10,16 @@ module DragonflySvg
11
10
 
12
11
  let(:xpath) { "./*[name()='svg']" }
13
12
  let(:attribute_name) { 'style' }
14
- let(:value) { 'margin: 50px;' }
13
+ let(:attribute_value) { 'margin: 50px;' }
15
14
 
16
15
  before do
17
- processor.call(svg, xpath, attribute_name, value)
16
+ processor.call(svg, xpath, attribute_name, attribute_value)
18
17
  end
19
18
 
20
19
  it 'sets attribute' do
21
20
  Nokogiri::XML(svg.data).xpath(xpath).count.must_equal 1
22
- Nokogiri::XML(svg.data).xpath(xpath).first.get_attribute('style').must_equal value
21
+ Nokogiri::XML(svg.data).xpath(xpath).first.get_attribute('style').must_equal attribute_value
23
22
  end
24
-
25
23
  end
26
24
  end
27
25
  end
@@ -3,7 +3,6 @@ require 'test_helper'
3
3
  module DragonflySvg
4
4
  module Processors
5
5
  describe SetDimensions do
6
-
7
6
  let(:app) { test_app.configure_with(:svg) }
8
7
  let(:processor) { DragonflySvg::Processors::SetDimensions.new }
9
8
  let(:analyser) { DragonflySvg::Analysers::SvgProperties.new }
@@ -20,7 +19,6 @@ module DragonflySvg
20
19
  it 'sets height' do
21
20
  analyser.call(svg)[:height].must_equal 600
22
21
  end
23
-
24
22
  end
25
23
  end
26
- end
24
+ end
@@ -3,7 +3,6 @@ require 'test_helper'
3
3
  module DragonflySvg
4
4
  module Processors
5
5
  describe SetNamespace do
6
-
7
6
  let(:app) { test_app.configure_with(:svg) }
8
7
  let(:processor) { DragonflySvg::Processors::SetNamespace.new }
9
8
  let(:svg) { Dragonfly::Content.new(app, SAMPLES_DIR.join('sample.svg')) }
@@ -17,7 +16,6 @@ module DragonflySvg
17
16
  processor.call(svg, 'custom_namespace')
18
17
  svg.data.must_include 'custom_namespace'
19
18
  end
20
-
21
19
  end
22
20
  end
23
- end
21
+ end
@@ -3,7 +3,6 @@ require 'test_helper'
3
3
  module DragonflySvg
4
4
  module Processors
5
5
  describe SetPreserveAspectRatio do
6
-
7
6
  let(:app) { test_app.configure_with(:svg) }
8
7
  let(:processor) { DragonflySvg::Processors::SetPreserveAspectRatio.new }
9
8
  let(:svg) { Dragonfly::Content.new(app, SAMPLES_DIR.join('sample.svg')) }
@@ -11,22 +10,21 @@ module DragonflySvg
11
10
  describe 'with default value' do
12
11
  it 'adds preserveAspectRatio attribute' do
13
12
  processor.call(svg)
14
- svg.data.must_include "preserveAspectRatio"
13
+ svg.data.must_include 'preserveAspectRatio'
15
14
  end
16
15
 
17
16
  it 'sets default value' do
18
17
  processor.call(svg)
19
- svg.data.must_include "xMinYMin meet"
18
+ svg.data.must_include 'xMinYMin meet'
20
19
  end
21
20
  end
22
21
 
23
22
  describe 'with specified value' do
24
23
  it 'adds preserveAspectRatio with specified value' do
25
24
  processor.call(svg, 'xMidYMid meet')
26
- svg.data.must_include "xMidYMid meet"
25
+ svg.data.must_include 'xMidYMid meet'
27
26
  end
28
27
  end
29
-
30
28
  end
31
29
  end
32
- end
30
+ end
@@ -3,7 +3,6 @@ require 'test_helper'
3
3
  module DragonflySvg
4
4
  module Processors
5
5
  describe SetViewBox do
6
-
7
6
  let(:app) { test_app.configure_with(:svg) }
8
7
  let(:processor) { DragonflySvg::Processors::SetViewBox.new }
9
8
  let(:svg) { Dragonfly::Content.new(app, SAMPLES_DIR.join('sample.svg')) }
@@ -15,7 +14,6 @@ module DragonflySvg
15
14
  it 'sets view box' do
16
15
  svg.data.must_include '0 0 400 600'
17
16
  end
18
-
19
17
  end
20
18
  end
21
- end
19
+ end
data/test/test_helper.rb CHANGED
@@ -13,9 +13,9 @@ SAMPLES_DIR = Pathname.new(File.expand_path('../../samples', __FILE__))
13
13
 
14
14
  # ---------------------------------------------------------------------
15
15
 
16
- def test_app name=nil
16
+ def test_app(name = nil)
17
17
  app = Dragonfly::App.instance(name)
18
18
  app.datastore = Dragonfly::MemoryDataStore.new
19
- app.secret = "test secret"
19
+ app.secret = 'test secret'
20
20
  app
21
- end
21
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dragonfly_svg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomas Celizna
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-30 00:00:00.000000000 Z
11
+ date: 2016-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dragonfly
@@ -125,7 +125,13 @@ files:
125
125
  - Rakefile
126
126
  - dragonfly_svg.gemspec
127
127
  - lib/dragonfly_svg.rb
128
+ - lib/dragonfly_svg/analysers/aspect_ratio_analyser.rb
129
+ - lib/dragonfly_svg/analysers/base.rb
130
+ - lib/dragonfly_svg/analysers/height_analyser.rb
131
+ - lib/dragonfly_svg/analysers/landscape_analyser.rb
132
+ - lib/dragonfly_svg/analysers/portrait_analyser.rb
128
133
  - lib/dragonfly_svg/analysers/svg_properties.rb
134
+ - lib/dragonfly_svg/analysers/width_analyser.rb
129
135
  - lib/dragonfly_svg/plugin.rb
130
136
  - lib/dragonfly_svg/processors/extend_ids.rb
131
137
  - lib/dragonfly_svg/processors/remove_namespaces.rb
@@ -135,6 +141,7 @@ files:
135
141
  - lib/dragonfly_svg/processors/set_preserve_aspect_ratio.rb
136
142
  - lib/dragonfly_svg/processors/set_view_box.rb
137
143
  - lib/dragonfly_svg/version.rb
144
+ - samples/sample.png
138
145
  - samples/sample.svg
139
146
  - test/dragonfly_svg/analysers/svg_properties_test.rb
140
147
  - test/dragonfly_svg/plugin_test.rb