Class: Cyberweb::TurnHtmlIntoCyberweb

Inherits:
Object
  • Object
show all
Defined in:
lib/cyberweb/standalone_classes/turn_html_into_cyberweb.rb

Overview

Cyberweb::TurnHtmlIntoCyberweb

Constant Summary collapse

N =
"\n"
TEST_THIS_INPUT =
#

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

#

initialize

#


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

#add(i) ⇒ Object

#

add

#


100
101
102
# File 'lib/cyberweb/standalone_classes/turn_html_into_cyberweb.rb', line 100

def add(i)
  @result << i
end

#addn(i) ⇒ Object

#

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

#convert_input_to_resultObject

#

convert_input_to_result

#


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)
        header  = match[1]
        content = match[2]
        add header+' "'+content+'"'+N
      end
    end
  }
  addn '}'
end

#debugObject

#

debug

#


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

#input?Boolean

#

input?

#

Returns:

  • (Boolean)


93
94
95
# File 'lib/cyberweb/standalone_classes/turn_html_into_cyberweb.rb', line 93

def input?
  @input
end

#resetObject

#

reset (reset tag)

#


69
70
71
# File 'lib/cyberweb/standalone_classes/turn_html_into_cyberweb.rb', line 69

def reset
  @result = ''.dup # We store the web_object-specific code here.
end

#result?Boolean

#

result?

#

Returns:

  • (Boolean)


76
77
78
# File 'lib/cyberweb/standalone_classes/turn_html_into_cyberweb.rb', line 76

def result?
  @result
end

#runObject

#

run (run tag)

#


166
167
168
# File 'lib/cyberweb/standalone_classes/turn_html_into_cyberweb.rb', line 166

def run
  convert_input_to_result
end

#set_input(i = nil) ⇒ Object

#

set_input

#


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_resultObject Also known as: report_result

#

show_result

#


159
160
161
# File 'lib/cyberweb/standalone_classes/turn_html_into_cyberweb.rb', line 159

def show_result
  e result?
end