Class: JsTreeBuilder
- Inherits:
-
Object
- Object
- JsTreeBuilder
- Defined in:
- lib/jstreebuilder.rb
Defined Under Namespace
Classes: TreeBuilder
Constant Summary collapse
- TREE_CSS =
%q[ /* Remove default bullets */ ul, #myUL { list-style-type: none; } /* Remove margins and padding from the parent ul */ #myUL { margin: 0; padding: 0; } /* Style the caret/arrow */ .caret { cursor: pointer; user-select: none; /* Prevent text selection */ } /* Create the caret/arrow with a unicode, and style it */ .caret::before { content: "\25B6"; color: black; display: inline-block; margin-right: 6px; } /* Rotate the caret/arrow icon when clicked on (using JavaScript) */ .caret-down::before { transform: rotate(90deg); } /* Hide the nested list */ .nested { display: none; } /* Show the nested list when the user clicks on the caret/arrow (with JavaScript) */ .active { display: block; } ]- TREE_JS =
"var toggler = document.getElementsByClassName(\"caret\");\nvar i;\n\nfor (i = 0; i < toggler.length; i++) {\n toggler[i].addEventListener(\"click\", function() {\n this.parentElement.querySelector(\".nested\").classList.toggle(\"active\");\n this.classList.toggle(\"caret-down\");\n });\n}\n"
Instance Attribute Summary collapse
-
#css ⇒ Object
readonly
Returns the value of attribute css.
-
#html ⇒ Object
readonly
Returns the value of attribute html.
-
#js ⇒ Object
readonly
Returns the value of attribute js.
Instance Method Summary collapse
-
#initialize(unknown = nil, options = {}) ⇒ JsTreeBuilder
constructor
A new instance of JsTreeBuilder.
- #to_css ⇒ Object
- #to_html ⇒ Object
- #to_js ⇒ Object
- #to_ul ⇒ Object
- #to_webpage ⇒ Object
- #to_xml ⇒ Object
Constructor Details
#initialize(unknown = nil, options = {}) ⇒ JsTreeBuilder
Returns a new instance of JsTreeBuilder.
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/jstreebuilder.rb', line 208 def initialize(unknown=nil, ={}) if unknown.is_a? String or unknown.is_a? Symbol then type = unkown.to_sym elsif unknown.is_a? Hash = {type: :tree}.merge(unknown) type = [:type] end @debug = [:debug] @types = i(tree) build(type, ) if type end |
Instance Attribute Details
#css ⇒ Object (readonly)
Returns the value of attribute css.
206 207 208 |
# File 'lib/jstreebuilder.rb', line 206 def css @css end |
#html ⇒ Object (readonly)
Returns the value of attribute html.
206 207 208 |
# File 'lib/jstreebuilder.rb', line 206 def html @html end |
#js ⇒ Object (readonly)
Returns the value of attribute js.
206 207 208 |
# File 'lib/jstreebuilder.rb', line 206 def js @js end |
Instance Method Details
#to_css ⇒ Object
225 226 227 |
# File 'lib/jstreebuilder.rb', line 225 def to_css() @css end |
#to_html ⇒ Object
229 230 231 |
# File 'lib/jstreebuilder.rb', line 229 def to_html() @html end |
#to_js ⇒ Object
233 234 235 |
# File 'lib/jstreebuilder.rb', line 233 def to_js() @js end |
#to_ul ⇒ Object
237 238 239 |
# File 'lib/jstreebuilder.rb', line 237 def to_ul() @ul end |
#to_webpage ⇒ Object
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
# File 'lib/jstreebuilder.rb', line 241 def to_webpage() a = RexleBuilder.build do |xml| xml.html do xml.head do xml. name: "viewport", content: \ "width=device-width, initial-scale=1" xml.style "\nbody {font-family: Arial;}\n\n" + @css end xml.body @ul end end doc = Rexle.new(a) doc.root.element('body').add \ Rexle::Element.new('script').add_text "\n" + @js.gsub(/^ +\/\/[^\n]+\n/,'') "<!DOCTYPE html>\n" + doc.xml(pretty: true, declaration: false)\ .gsub(/<\/div>/,'\0' + "\n").gsub(/\n *<!--[^>]+>/,'') end |
#to_xml ⇒ Object
265 266 267 |
# File 'lib/jstreebuilder.rb', line 265 def to_xml() @xml end |