Module: Sevgi::Graphics::Mixtures::Include

Defined in:
lib/sevgi/graphics/mixtures/include.rb

Overview

DSL helpers for including derendered SVG/XML fragments.

Instance Method Summary collapse

Instance Method Details

#Include(file, id, omit: nil) ⇒ Sevgi::Graphics::Element?

Includes a derendered node matching an id. SVG/XML content is treated as data and is not evaluated as Ruby source.

Examples:

Import a fragment without editor ids and inline styles

Sevgi::Graphics.SVG do
  Include "badge.svg", "mark", omit: %i[id style]
end

Parameters:

  • file (String)

    source SVG/XML file

  • id (String, Symbol)

    source node id

  • omit (String, Symbol, Array<String, Symbol>, nil) (defaults to: nil)

    exact attribute name or names omitted from the selected subtree after id selection

Returns:

Raises:

  • (Sevgi::ArgumentError)

    when the file is absent or XML content is malformed, rootless, or lacks the id

  • (SystemCallError)

    when the file cannot be read

  • (Sevgi::MissingComponentError)

    when sevgi/derender is unavailable



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/sevgi/graphics/mixtures/include.rb', line 34

module Include
  require "sevgi/derender"

  # Includes a derendered node matching an id.
  #
  # SVG/XML file content is treated as data and is not evaluated as Ruby source.
  # @param file [String] source SVG/XML file
  # @param id [String, Symbol] source node id
  # @param omit [String, Symbol, Array<String, Symbol>, nil] exact attribute name or names omitted from the selected
  #   subtree after id selection
  # @return [Sevgi::Graphics::Element, nil] included element, or nil when the selected node produces no graphics
  #   output
  # @raise [Sevgi::ArgumentError] when the file cannot be found, file content is malformed or rootless, or the id is
  #   absent
  # @raise [SystemCallError] when the file cannot be read
  # @raise [Sevgi::MissingComponentError] when sevgi/derender is unavailable
  def Include(file, id, omit: nil) = Derender.evaluate_file(file, self, id:, omit:)

  # Includes the children of a derendered node matching an id.
  #
  # SVG/XML file content is treated as data and is not evaluated as Ruby source.
  # @param file [String] source SVG/XML file
  # @param id [String, Symbol] source node id
  # @param omit [String, Symbol, Array<String, Symbol>, nil] exact attribute name or names omitted from the selected
  #   subtree after id selection
  # @return [Array<Sevgi::Graphics::Element>] immutable included-child snapshot
  # @raise [Sevgi::ArgumentError] when the file cannot be found, file content is malformed or rootless, or the id is
  #   absent
  # @raise [SystemCallError] when the file cannot be read
  # @raise [Sevgi::MissingComponentError] when sevgi/derender is unavailable
  def IncludeChildren(file, id, omit: nil) = Derender.evaluate_children_file(file, self, id:, omit:)
rescue ::LoadError => e
  raise unless e.path == "sevgi/derender"

  # @overload IncludeChildren(file, id, omit: nil)
  #   Raises because sevgi/derender is unavailable.
  #   @param file [String] source SVG/XML file
  #   @param id [String, Symbol] source node id
  #   @param omit [String, Symbol, Array<String, Symbol>, nil] ignored because the component is unavailable
  #   @return [void]
  #   @raise [Sevgi::MissingComponentError] always
  def IncludeChildren(...) = MissingComponentError.("sevgi/derender")

  # @overload Include(file, id, omit: nil)
  #   Raises because sevgi/derender is unavailable.
  #   @param file [String] source SVG/XML file
  #   @param id [String, Symbol] source node id
  #   @param omit [String, Symbol, Array<String, Symbol>, nil] ignored because the component is unavailable
  #   @return [void]
  #   @raise [Sevgi::MissingComponentError] always
  def Include(...) = MissingComponentError.("sevgi/derender")
end

#IncludeChildren(file, id, omit: nil) ⇒ Array<Sevgi::Graphics::Element>

Includes the children of a derendered node matching an id. SVG/XML content is treated as data and is not evaluated as Ruby source.

Parameters:

  • file (String)

    source SVG/XML file

  • id (String, Symbol)

    source node id

  • omit (String, Symbol, Array<String, Symbol>, nil) (defaults to: nil)

    exact attribute name or names omitted from the selected subtree after id selection

Returns:

Raises:

  • (Sevgi::ArgumentError)

    when the file is absent or XML content is malformed, rootless, or lacks the id

  • (SystemCallError)

    when the file cannot be read

  • (Sevgi::MissingComponentError)

    when sevgi/derender is unavailable



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/sevgi/graphics/mixtures/include.rb', line 34

module Include
  require "sevgi/derender"

  # Includes a derendered node matching an id.
  #
  # SVG/XML file content is treated as data and is not evaluated as Ruby source.
  # @param file [String] source SVG/XML file
  # @param id [String, Symbol] source node id
  # @param omit [String, Symbol, Array<String, Symbol>, nil] exact attribute name or names omitted from the selected
  #   subtree after id selection
  # @return [Sevgi::Graphics::Element, nil] included element, or nil when the selected node produces no graphics
  #   output
  # @raise [Sevgi::ArgumentError] when the file cannot be found, file content is malformed or rootless, or the id is
  #   absent
  # @raise [SystemCallError] when the file cannot be read
  # @raise [Sevgi::MissingComponentError] when sevgi/derender is unavailable
  def Include(file, id, omit: nil) = Derender.evaluate_file(file, self, id:, omit:)

  # Includes the children of a derendered node matching an id.
  #
  # SVG/XML file content is treated as data and is not evaluated as Ruby source.
  # @param file [String] source SVG/XML file
  # @param id [String, Symbol] source node id
  # @param omit [String, Symbol, Array<String, Symbol>, nil] exact attribute name or names omitted from the selected
  #   subtree after id selection
  # @return [Array<Sevgi::Graphics::Element>] immutable included-child snapshot
  # @raise [Sevgi::ArgumentError] when the file cannot be found, file content is malformed or rootless, or the id is
  #   absent
  # @raise [SystemCallError] when the file cannot be read
  # @raise [Sevgi::MissingComponentError] when sevgi/derender is unavailable
  def IncludeChildren(file, id, omit: nil) = Derender.evaluate_children_file(file, self, id:, omit:)
rescue ::LoadError => e
  raise unless e.path == "sevgi/derender"

  # @overload IncludeChildren(file, id, omit: nil)
  #   Raises because sevgi/derender is unavailable.
  #   @param file [String] source SVG/XML file
  #   @param id [String, Symbol] source node id
  #   @param omit [String, Symbol, Array<String, Symbol>, nil] ignored because the component is unavailable
  #   @return [void]
  #   @raise [Sevgi::MissingComponentError] always
  def IncludeChildren(...) = MissingComponentError.("sevgi/derender")

  # @overload Include(file, id, omit: nil)
  #   Raises because sevgi/derender is unavailable.
  #   @param file [String] source SVG/XML file
  #   @param id [String, Symbol] source node id
  #   @param omit [String, Symbol, Array<String, Symbol>, nil] ignored because the component is unavailable
  #   @return [void]
  #   @raise [Sevgi::MissingComponentError] always
  def Include(...) = MissingComponentError.("sevgi/derender")
end