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; } ]- SIDEBAR_CSS =
TREE_CSS + %q[ body { font-family: "Lato", sans-serif; } .sidenav { width: 25%; position: fixed; z-index: 1; top: 20px; left: 10px; background: #eee; overflow-x: hidden; padding: 12px 0; } .sidenav a { padding: 2px 8px 2px 6px; text-decoration: none; font-size: 23px; color: #2166F3; } .sidenav a:hover { color: #064579; } .main { margin-left: 25%; /* Same width as the sidebar + left position in px */ font-size: 26px; /* Increased text to enable scrolling */ padding: 0px 10px; } @media screen and (max-height: 450px) { .sidenav {padding-top: 15px;} .sidenav a {font-size: 19 px;} } ]
- 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"- SIDEBAR_JS =
TREE_JS
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.
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 |
# File 'lib/jstreebuilder.rb', line 251 def initialize(unknown=nil, ={}) if unknown.is_a? String or unknown.is_a? Symbol then type = unknown.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.
249 250 251 |
# File 'lib/jstreebuilder.rb', line 249 def css @css end |
#html ⇒ Object (readonly)
Returns the value of attribute html.
249 250 251 |
# File 'lib/jstreebuilder.rb', line 249 def html @html end |
#js ⇒ Object (readonly)
Returns the value of attribute js.
249 250 251 |
# File 'lib/jstreebuilder.rb', line 249 def js @js end |
Instance Method Details
#to_css ⇒ Object
268 269 270 |
# File 'lib/jstreebuilder.rb', line 268 def to_css() @css end |
#to_html ⇒ Object
272 273 274 |
# File 'lib/jstreebuilder.rb', line 272 def to_html() @html end |
#to_js ⇒ Object
276 277 278 |
# File 'lib/jstreebuilder.rb', line 276 def to_js() @js end |
#to_ul ⇒ Object
280 281 282 |
# File 'lib/jstreebuilder.rb', line 280 def to_ul() @ul end |
#to_webpage ⇒ Object
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 |
# File 'lib/jstreebuilder.rb', line 284 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
308 309 310 |
# File 'lib/jstreebuilder.rb', line 308 def to_xml() @xml end |