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
DEFAULT_SPRITE_NAME =
"sprite"
VERSION =
"1.0.2"

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.



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/svg_sprite.rb', line 44

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.



41
42
43
# File 'lib/svg_sprite.rb', line 41

def css_path
  @css_path
end

#fillObject (readonly)

Returns the value of attribute fill.



41
42
43
# File 'lib/svg_sprite.rb', line 41

def fill
  @fill
end

#inputObject (readonly)

Returns the value of attribute input.



41
42
43
# File 'lib/svg_sprite.rb', line 41

def input
  @input
end

#input_filesObject (readonly)

Returns the value of attribute input_files.



41
42
43
# File 'lib/svg_sprite.rb', line 41

def input_files
  @input_files
end

#nameObject (readonly)

Returns the value of attribute name.



41
42
43
# File 'lib/svg_sprite.rb', line 41

def name
  @name
end

#optimizeObject (readonly)

Returns the value of attribute optimize.



41
42
43
# File 'lib/svg_sprite.rb', line 41

def optimize
  @optimize
end

#sprite_pathObject (readonly)

Returns the value of attribute sprite_path.



41
42
43
# File 'lib/svg_sprite.rb', line 41

def sprite_path
  @sprite_path
end

#strokeObject (readonly)

Returns the value of attribute stroke.



41
42
43
# File 'lib/svg_sprite.rb', line 41

def stroke
  @stroke
end

Class Method Details

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



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/svg_sprite.rb', line 21

def self.call(
  input:,
  sprite_path:,
  css_path:,
  name: DEFAULT_SPRITE_NAME,
  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
  ).tap(&:call)
end

Instance Method Details

#callObject



57
58
59
60
61
# File 'lib/svg_sprite.rb', line 57

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