Class: SvgSprite

Inherits:
Object
  • Object
show all
Defined in:
lib/svg_sprite.rb,
lib/svg_sprite/cli.rb,
lib/svg_sprite/svg.rb,
lib/svg_sprite/version.rb

Defined Under Namespace

Classes: CLI, SVG

Constant Summary collapse

NOKOGIRI_SAVE_OPTIONS =
{
  save_with: Nokogiri::XML::Node::SaveOptions::DEFAULT_XML |
             Nokogiri::XML::Node::SaveOptions::NO_DECLARATION
}.freeze
VERSION =
"1.0.0"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, input:, sprite_path:, css_path:, optimize:, stroke:, fill:) ⇒ SvgSprite

Returns a new instance of SvgSprite.



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/svg_sprite.rb', line 37

def initialize(
  name:, input:, sprite_path:, css_path:, optimize:, stroke:, fill:
)
  @name = name
  @input = input
  @input_files = Dir["#{input}/**/*.svg"].sort
  @sprite_path = sprite_path
  @css_path = css_path
  @optimize = optimize
  @stroke = stroke
  @fill = fill
end

Instance Attribute Details

#css_pathObject (readonly)

Returns the value of attribute css_path.



34
35
36
# File 'lib/svg_sprite.rb', line 34

def css_path
  @css_path
end

#fillObject (readonly)

Returns the value of attribute fill.



34
35
36
# File 'lib/svg_sprite.rb', line 34

def fill
  @fill
end

#inputObject (readonly)

Returns the value of attribute input.



34
35
36
# File 'lib/svg_sprite.rb', line 34

def input
  @input
end

#input_filesObject (readonly)

Returns the value of attribute input_files.



34
35
36
# File 'lib/svg_sprite.rb', line 34

def input_files
  @input_files
end

#nameObject (readonly)

Returns the value of attribute name.



34
35
36
# File 'lib/svg_sprite.rb', line 34

def name
  @name
end

#optimizeObject (readonly)

Returns the value of attribute optimize.



34
35
36
# File 'lib/svg_sprite.rb', line 34

def optimize
  @optimize
end

#sprite_pathObject (readonly)

Returns the value of attribute sprite_path.



34
35
36
# File 'lib/svg_sprite.rb', line 34

def sprite_path
  @sprite_path
end

#strokeObject (readonly)

Returns the value of attribute stroke.



34
35
36
# File 'lib/svg_sprite.rb', line 34

def stroke
  @stroke
end

Class Method Details

.call(name:, input:, sprite_path:, css_path:, optimize: true, stroke: nil, fill: nil) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/svg_sprite.rb', line 19

def self.call(
  name:, input:, sprite_path:, css_path:,
  optimize: true, stroke: nil, fill: nil
)
  new(
    name: name,
    input: input,
    sprite_path: sprite_path,
    css_path: css_path,
    optimize: optimize,
    stroke: stroke,
    fill: fill
  ).call
end

Instance Method Details

#callObject



50
51
52
53
# File 'lib/svg_sprite.rb', line 50

def call
  save_file sprite_path, svg_sprite
  save_file css_path, manifest(css_definitions.chomp)
end