Class: HtmlList
- Inherits:
-
Object
- Object
- HtmlList
- Defined in:
- lib/text-to-html/html_list.rb
Overview
function: pulls list of text w/line breaks from clipboard, adds <li></li> to line, and puts back on clipboard
Instance Method Summary collapse
-
#initialize(input, h_class) ⇒ HtmlList
constructor
A new instance of HtmlList.
- #ol ⇒ Object
- #to_list ⇒ Object
- #ul ⇒ Object
- #use_class ⇒ Object
- #verbose ⇒ Object
Constructor Details
#initialize(input, h_class) ⇒ HtmlList
Returns a new instance of HtmlList.
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/text-to-html/html_list.rb', line 5 def initialize(input, h_class) # String to be parsed @input = input @hclass = h_class # Options @verbose = false @ul = false @ol = false @use_class = false end |
Instance Method Details
#ol ⇒ Object
50 51 52 |
# File 'lib/text-to-html/html_list.rb', line 50 def ol @ol = true end |
#to_list ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/text-to-html/html_list.rb', line 17 def to_list raw_in = @input.gsub("\t", '').gsub("\r", '').gsub("\"", '').split("\n") puts raw_in.inspect if @verbose p_string = "" p_string = "<ul#{(" class=\"" + @hclass + "\"") if @use_class}>\n" if @ul p_string = "<ol#{(" class=\"" + @hclass + "\"") if @use_class}>\n" if @ol raw_in.each do | line | if @ul || @ol || @ul_f p_string << "\t<li>\n\t\t#{line}\n\t</li>\n" else p_string << "<li>\n\t#{line}\n</li>\n" end end p_string << "</ul>\n" if @ul || @ul_f p_string << "</ol>\n" if @ol p_string.chomp! puts p_string if @verbose return p_string end |
#ul ⇒ Object
46 47 48 |
# File 'lib/text-to-html/html_list.rb', line 46 def ul @ul = true end |
#use_class ⇒ Object
54 55 56 |
# File 'lib/text-to-html/html_list.rb', line 54 def use_class @use_class = true end |
#verbose ⇒ Object
42 43 44 |
# File 'lib/text-to-html/html_list.rb', line 42 def verbose @verbose = true end |