Class: EZML::Buffer
Constant Summary
Constants included
from Helpers
Helpers::HTML_ESCAPE, Helpers::HTML_ESCAPE_ONCE_REGEX, Helpers::HTML_ESCAPE_REGEX
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Util
#balance, #check_encoding, #check_ezml_encoding, #contains_interpolation?, #handle_interpolation, #html_safe, #human_indentation, #inspect_obj, #silence_warnings, #unescape_interpolation
Methods included from Helpers
action_view?, #block_is_ezml?, #capture_ezml, #escape_once, #ezml_concat, #ezml_indent, #ezml_tag, #ezml_tag_if, #find_and_preserve, #html_attrs, #html_escape, #init_ezml_helpers, #is_ezml?, #list_of, #non_ezml, #precede, #preserve, #succeed, #surround, #tab_down, #tab_up, #with_tabs
Constructor Details
#initialize(upper = nil, options = {}) ⇒ Buffer
Returns a new instance of Buffer.
46
47
48
49
50
51
52
53
54
55
56
57
|
# File 'lib/ezml/buffer.rb', line 46
def initialize(upper = nil, options = {})
@active = true
@upper = upper
@options = Options.buffer_defaults
@options = @options.merge(options) unless options.empty?
@buffer = new_encoded_string
@tabulation = 0
@real_tabs = 0
end
|
Instance Attribute Details
#active=(value) ⇒ Object
Sets the attribute active
11
12
13
|
# File 'lib/ezml/buffer.rb', line 11
def active=(value)
@active = value
end
|
Returns the value of attribute buffer.
7
8
9
|
# File 'lib/ezml/buffer.rb', line 7
def buffer
@buffer
end
|
#capture_position ⇒ Object
Returns the value of attribute capture_position.
10
11
12
|
# File 'lib/ezml/buffer.rb', line 10
def capture_position
@capture_position
end
|
Returns the value of attribute options.
8
9
10
|
# File 'lib/ezml/buffer.rb', line 8
def options
@options
end
|
Returns the value of attribute upper.
9
10
11
|
# File 'lib/ezml/buffer.rb', line 9
def upper
@upper
end
|
Instance Method Details
#active? ⇒ Boolean
33
34
35
|
# File 'lib/ezml/buffer.rb', line 33
def active?
@active
end
|
#adjust_tabs(tab_change) ⇒ Object
72
73
74
|
# File 'lib/ezml/buffer.rb', line 72
def adjust_tabs(tab_change)
@real_tabs += tab_change
end
|
#attributes(class_id, obj_ref, *attributes_hashes) ⇒ Object
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/ezml/buffer.rb', line 76
def attributes(class_id, obj_ref, *attributes_hashes)
attributes = class_id
attributes_hashes.each do |old|
result = {}
old.each { |k, v| result[k.to_s] = v }
AttributeBuilder.merge_attributes!(attributes, result)
end
AttributeBuilder.merge_attributes!(attributes, parse_object_ref(obj_ref)) if obj_ref
AttributeBuilder.build_attributes(
html?, @options[:attr_wrapper], @options[:escape_attrs], @options[:hyphenate_data_attrs], attributes)
end
|
#fix_textareas!(input) ⇒ Object
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
# File 'lib/ezml/buffer.rb', line 97
def fix_textareas!(input)
return input unless input.include?('<textarea'.freeze)
pattern = /<(textarea)([^>]*)>(\n|
)(.*?)<\/textarea>/im
input.gsub!(pattern) do |s|
match = pattern.match(s)
content = match[4]
if match[3] == '
'
content.sub!(/\A /, ' ')
else
content.sub!(/\A[ ]*/, '')
end
"<#{match[1]}#{match[2]}>\n#{content}</#{match[1]}>"
end
input
end
|
#html4? ⇒ Boolean
21
22
23
|
# File 'lib/ezml/buffer.rb', line 21
def html4?
@options[:format] == :html4
end
|
#html5? ⇒ Boolean
25
26
27
|
# File 'lib/ezml/buffer.rb', line 25
def html5?
@options[:format] == :html5
end
|
#html? ⇒ Boolean
17
18
19
|
# File 'lib/ezml/buffer.rb', line 17
def html?
html4? or html5?
end
|
#push_text(text, tab_change, dont_tab_up) ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/ezml/buffer.rb', line 59
def push_text(text, tab_change, dont_tab_up)
if @tabulation > 0
text.gsub!(/^(?!\s+$)/m, tabs)
text.sub!(tabs, '') if dont_tab_up
end
@real_tabs += tab_change
@buffer << text
end
|
88
89
90
91
92
93
94
95
|
# File 'lib/ezml/buffer.rb', line 88
def rstrip!
if capture_position.nil?
buffer.rstrip!
return
end
buffer << buffer.slice!(capture_position..-1).rstrip
end
|
#tabulation ⇒ Object
37
38
39
|
# File 'lib/ezml/buffer.rb', line 37
def tabulation
@real_tabs + @tabulation
end
|
#tabulation=(val) ⇒ Object
41
42
43
44
|
# File 'lib/ezml/buffer.rb', line 41
def tabulation=(val)
val = val - @real_tabs
@tabulation = val > -1 ? val : 0
end
|
#toplevel? ⇒ Boolean
29
30
31
|
# File 'lib/ezml/buffer.rb', line 29
def toplevel?
upper.nil?
end
|
#xhtml? ⇒ Boolean
13
14
15
|
# File 'lib/ezml/buffer.rb', line 13
def xhtml?
not html?
end
|