Module: Sumi::Graphics::Mixtures::Include

Defined in:
graphics/lib/sumi/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) ⇒ Sumi::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

Sumi::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:



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 'graphics/lib/sumi/graphics/mixtures/include.rb', line 34

module Include
  require "sumi/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 [Sumi::Graphics::Element, nil] included element, or nil when the selected node produces no graphics
  #   output
  # @raise [Sumi::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 [Sumi::MissingComponentError] when sumi/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<Sumi::Graphics::Element>] immutable included-child snapshot
  # @raise [Sumi::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 [Sumi::MissingComponentError] when sumi/derender is unavailable
  def IncludeChildren(file, id, omit: nil) = Derender.evaluate_children_file(file, self, id:, omit:)
rescue ::LoadError => e
  raise unless e.path == "sumi/derender"

  # @overload IncludeChildren(file, id, omit: nil)
  #   Raises because sumi/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 [Sumi::MissingComponentError] always
  def IncludeChildren(...) = MissingComponentError.("sumi/derender")

  # @overload Include(file, id, omit: nil)
  #   Raises because sumi/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 [Sumi::MissingComponentError] always
  def Include(...) = MissingComponentError.("sumi/derender")
end

#IncludeChildren(file, id, omit: nil) ⇒ Array<Sumi::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:



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 'graphics/lib/sumi/graphics/mixtures/include.rb', line 34

module Include
  require "sumi/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 [Sumi::Graphics::Element, nil] included element, or nil when the selected node produces no graphics
  #   output
  # @raise [Sumi::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 [Sumi::MissingComponentError] when sumi/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<Sumi::Graphics::Element>] immutable included-child snapshot
  # @raise [Sumi::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 [Sumi::MissingComponentError] when sumi/derender is unavailable
  def IncludeChildren(file, id, omit: nil) = Derender.evaluate_children_file(file, self, id:, omit:)
rescue ::LoadError => e
  raise unless e.path == "sumi/derender"

  # @overload IncludeChildren(file, id, omit: nil)
  #   Raises because sumi/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 [Sumi::MissingComponentError] always
  def IncludeChildren(...) = MissingComponentError.("sumi/derender")

  # @overload Include(file, id, omit: nil)
  #   Raises because sumi/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 [Sumi::MissingComponentError] always
  def Include(...) = MissingComponentError.("sumi/derender")
end