Class: Cyberweb::TurnHtmlIntoCyberweb
- Inherits:
-
Object
- Object
- Cyberweb::TurnHtmlIntoCyberweb
show all
- Defined in:
- lib/cyberweb/standalone_classes/turn_html_into_cyberweb.rb
Overview
Cyberweb::TurnHtmlIntoCyberweb
Constant Summary
collapse
- N =
"\n"
- TEST_THIS_INPUT =
#
This is the input that we can test.
#
'<!DOCTYPE html>
<html>
<body>
<h1>This is heading 1</h1>
<h2>This is heading 2</h2>
<h3>This is heading 3</h3>
<h4>This is heading 4</h4>
<h5>This is heading 5</h5>
<h6>This is heading 6</h6>
</body>
</html>
'
Instance Method Summary
collapse
Constructor Details
#initialize(i = nil, run_already = true) ⇒ TurnHtmlIntoCyberweb
57
58
59
60
61
62
63
64
|
# File 'lib/cyberweb/standalone_classes/turn_html_into_cyberweb.rb', line 57
def initialize(
i = nil,
run_already = true
)
reset
set_input(i)
run if run_already
end
|
Instance Method Details
100
101
102
|
# File 'lib/cyberweb/standalone_classes/turn_html_into_cyberweb.rb', line 100
def add(i)
@result << i
end
|
#
addn
As add() but with a newline.
#
109
110
111
|
# File 'lib/cyberweb/standalone_classes/turn_html_into_cyberweb.rb', line 109
def addn(i)
add(i+N)
end
|
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
# File 'lib/cyberweb/standalone_classes/turn_html_into_cyberweb.rb', line 116
def convert_input_to_result
_ = input?
_ = _.split(N) if _.is_a? String
add "require 'cyberweb/autoinclude'"+N+N
addn 'english {'
addn "title 'SELF'"
addn "jquery '+'"
_.each {|line|
if line.include? '!DOCTTYPE html'
add 'doctype :html'+N+N
elsif line.include? '</body>'
add 'cbody'+N
elsif line.include? '</html>'
add 'chtml'+N
elsif line.include? '<html'
add 'html'+N+N
elsif line.include? 'body'
add 'body'+N
elsif line.empty?
add N
else
if line =~ /\<h\d+/ and line =~ /\<\/h\d+/
match = /\<(h\d+)\>(.+)\<\/h\d+\>/.match(line)
= match[1]
content = match[2]
add +' "'+content+'"'+N
end
end
}
addn '}'
end
|
151
152
153
154
|
# File 'lib/cyberweb/standalone_classes/turn_html_into_cyberweb.rb', line 151
def debug
opn; e 'The original input was:'
e input?
end
|
93
94
95
|
# File 'lib/cyberweb/standalone_classes/turn_html_into_cyberweb.rb', line 93
def input?
@input
end
|
69
70
71
|
# File 'lib/cyberweb/standalone_classes/turn_html_into_cyberweb.rb', line 69
def reset
@result = ''.dup end
|
#result? ⇒ Boolean
76
77
78
|
# File 'lib/cyberweb/standalone_classes/turn_html_into_cyberweb.rb', line 76
def result?
@result
end
|
166
167
168
|
# File 'lib/cyberweb/standalone_classes/turn_html_into_cyberweb.rb', line 166
def run
convert_input_to_result
end
|
83
84
85
86
87
88
|
# File 'lib/cyberweb/standalone_classes/turn_html_into_cyberweb.rb', line 83
def set_input(i = nil)
i = i.first i.is_a? Array
i = TEST_THIS_INPUT if i.nil?
i = i.to_s.dup if i
@input = i
end
|
#show_result ⇒ Object
Also known as:
report_result
159
160
161
|
# File 'lib/cyberweb/standalone_classes/turn_html_into_cyberweb.rb', line 159
def show_result
e result?
end
|