Class: RailroadDiagrams::Style
- Inherits:
-
Object
- Object
- RailroadDiagrams::Style
- Defined in:
- lib/railroad_diagrams/style.rb,
sig/generated/railroad_diagrams/style.rbs
Overview
Custom CSS that can be embedded in a standalone diagram.
Class Method Summary collapse
Instance Method Summary collapse
- #add(parent) ⇒ Style
- #format ⇒ Style
-
#initialize(css) ⇒ Style
constructor
A new instance of Style.
- #render_svg(_context) ⇒ Object
- #text_diagram ⇒ TextDiagram
- #to_s ⇒ String
- #write_svg(write) ⇒ void
Constructor Details
#initialize(css) ⇒ Style
Returns a new instance of Style.
11 12 13 |
# File 'lib/railroad_diagrams/style.rb', line 11 def initialize(css) @css = css end |
Class Method Details
.default_style ⇒ String
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 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 |
# File 'lib/railroad_diagrams/style.rb', line 19 def default_style <<~CSS * { color: #333333; } svg.railroad-diagram { background-color: white; } svg.railroad-diagram path { stroke-width:3; stroke:black; fill:rgba(0,0,0,0); } svg.railroad-diagram text { font:bold 14px monospace; text-anchor:middle; white-space: pre; } svg.railroad-diagram text.diagram-text { font-size: 12px; } svg.railroad-diagram text.diagram-arrow { font-size: 16px; } svg.railroad-diagram path.diagram-text { stroke-width: 3; stroke: #333333; fill: white; cursor: help; } svg.railroad-diagram g.diagram-text:hover path.diagram-text { fill: #eee; } svg.railroad-diagram text.label { text-anchor:start; } svg.railroad-diagram text.comment { font:italic 12px monospace; } svg.railroad-diagram rect { stroke-width:3; stroke: #333333; fill:hsl(120,100%,90%); } svg.railroad-diagram path { stroke: #333333; } svg.railroad-diagram .terminal rect { fill: hsl(190, 100%, 83%); } svg.railroad-diagram .non-terminal rect { fill: hsl(223, 100%, 83%); } svg.railroad-diagram rect.group-box { stroke: gray; stroke-dasharray: 10 5; fill: none; } CSS end |
Instance Method Details
#add(parent) ⇒ Style
88 89 90 91 |
# File 'lib/railroad_diagrams/style.rb', line 88 def add(parent) parent.children.push(self) self end |
#render_svg(_context) ⇒ Object
109 110 111 |
# File 'lib/railroad_diagrams/style.rb', line 109 def render_svg(_context) Svg::StyleText.new(@css) end |
#text_diagram ⇒ TextDiagram
99 100 101 |
# File 'lib/railroad_diagrams/style.rb', line 99 def text_diagram TextDiagram.new(0, 0, []) end |
#to_s ⇒ String
82 83 84 |
# File 'lib/railroad_diagrams/style.rb', line 82 def to_s "Style(#{@css})" end |
#write_svg(write) ⇒ void
This method returns an undefined value.
105 106 107 |
# File 'lib/railroad_diagrams/style.rb', line 105 def write_svg(write) Writer.wrap(write).call(Svg::Serializer.call(render_svg(nil))) end |