Class: Weskit::WML::Formatter
Instance Attribute Summary collapse
-
#separator ⇒ Object
readonly
Returns the value of attribute separator.
Class Method Summary collapse
Instance Method Summary collapse
- #format(item, indentation = 0) ⇒ Object
- #format_detached(item, formatter = nil) ⇒ Object
- #indent(content, width = 0) ⇒ Object
-
#initialize(options = {}) ⇒ Formatter
constructor
A new instance of Formatter.
Constructor Details
#initialize(options = {}) ⇒ Formatter
Returns a new instance of Formatter.
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/weskit/wml/formatter.rb', line 26 def initialize = {} = .merge @attr_formatter = [:attr_formatter].new self @elem_formatter = [:elem_formatter].new self @indent = [:indent] @separator = [:separator] self end |
Instance Attribute Details
#separator ⇒ Object (readonly)
Returns the value of attribute separator.
5 6 7 |
# File 'lib/weskit/wml/formatter.rb', line 5 def separator @separator end |
Class Method Details
.color ⇒ Object
48 49 50 |
# File 'lib/weskit/wml/formatter.rb', line 48 def color @color ||= new end |
.default ⇒ Object
52 53 54 |
# File 'lib/weskit/wml/formatter.rb', line 52 def default @default or plain end |
.default=(item) ⇒ Object
56 57 58 59 |
# File 'lib/weskit/wml/formatter.rb', line 56 def default= item Mixins::Validator.raise_unless Formatter, item @default = item end |
.plain ⇒ Object
61 62 63 |
# File 'lib/weskit/wml/formatter.rb', line 61 def plain @plain ||= new end |
Instance Method Details
#format(item, indentation = 0) ⇒ Object
7 8 9 10 11 12 |
# File 'lib/weskit/wml/formatter.rb', line 7 def format item, indentation = 0 case item when Attribute then @attr_formatter.format item, indentation when Element then @elem_formatter.format item, indentation end end |
#format_detached(item, formatter = nil) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/weskit/wml/formatter.rb', line 14 def format_detached item, formatter = nil formatter ||= item.formatter duplicate = item.dup.detach duplicate.formatter = formatter format item end |
#indent(content, width = 0) ⇒ Object
22 23 24 |
# File 'lib/weskit/wml/formatter.rb', line 22 def indent content, width = 0 @indent * width + "#{content}" end |