Class: Twb::HTMLListCollapsible

Inherits:
Object
  • Object
show all
Defined in:
lib/twb/htmllistcollapsible.rb,
lib/twb/util/htmllistcollapsible.rb

Constant Summary collapse

@@doc =
Nokogiri::HTML::Document.parse  "    <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n    <html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\">\n    <head>\n        <title>TWB Documentation</title>\n    \n        <style type=\"text/css\">\n            body, a {\n                color: #3B4C56;\n                font-family: sans-serif;\n                font-size: 14px;\n                text-decoration: none;\n            }\n            #pgtitle\n            {\n               margin: 0px 0px 20px;\n               font-size: 14pt;\n               text-align: center;\n            }\n            a{\n               cursor:pointer;\n            }\n            .tree ul {\n                list-style: none outside none;\n            }\n            .tree li a {\n                line-height: 25px;\n            }\n            .tree > ul > li > a {\n                color: #3B4C56;\n                display: block;\n                font-weight: normal;\n                position: relative;\n                text-decoration: none;\n            }\n            .tree li.parent > a {\n                padding: 0 0 0 28px;\n            }\n            .tree li.parent > a:before {\n                background-image: url(\"UpLeftArrowsNav.png\");\n                background-position: 20px center;\n                 content: \"\";\n                display: block;\n                height: 20px;\n                left: 0;\n                position: absolute;\n                top: 2px;\n                vertical-align: middle;\n                width: 20px;\n            }\n            .tree ul li.active > a:before {\n                background-position: 0 center;\n            }\n            .tree ul li ul {\n                border-left: 1px solid #D9DADB;\n                display: none;\n                margin: 0 0 0 12px;\n                overflow: hidden;\n                padding: 0 0 0 25px;\n            }\n            .tree ul li ul li {\n                position: relative;\n            }\n            .tree ul li ul li:before {\n                border-bottom: 1px dashed #E2E2E3;\n                content: \"\";\n                left: -20px;\n                position: absolute;\n                top: 12px;\n                width: 15px;\n            }\n            #wrapper {\n                margin: 0 auto;\n                width: 300px;\n            }\n        </style>\n    \n        <script src=\"http://code.jquery.com/jquery-1.7.2.min.js\" type=\"text/javascript\" > </script>\n    \n        <script type=\"text/javascript\">\n            $( document ).ready( function( ) {\n                    $( '.tree li' ).each( function() {\n                            if( $( this ).children( 'ul' ).length > 0 ) {\n                                    $( this ).addClass( 'parent' );\n                            }\n                    });\n    \n                    $( '.tree li.parent > a' ).click( function( ) {\n                            $( this ).parent().toggleClass( 'active' );\n                            $( this ).parent().children( 'ul' ).slideToggle( 'fast' );\n                    });\n    \n                    $( '#all' ).click( function() {\n    \n                        $( '.tree li' ).each( function() {\n                            $( this ).toggleClass( 'active' );\n                            $( this ).children( 'ul' ).slideToggle( 'fast' );\n                        });\n                    });\n    \n                    $( '.tree li' ).each( function() {\n                            $( this ).toggleClass( 'active' );\n                            $( this ).children( 'ul' ).slideToggle( 'fast' );\n                    });\n    \n            });\n    \n        </script>\n    \n    </head>\n    <body>\n        <div id=\"pgtitle\">\n            Expandable nested list.\n        </div>\n        <div id=\"wrapper\">\n        <div class=\"tree\">\n        <button id=\"all\">Toggle all</button>\n        <ul>\n        </ul>\n        </div>\n        </div>\n    \n    </body>\n    </html>\n"

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ HTMLListCollapsible

Returns a new instance of HTMLListCollapsible.



150
151
152
153
154
155
# File 'lib/twb/util/htmllistcollapsible.rb', line 150

def initialize(hash)
  @htmldoc = @@doc
  @list    = HashToHTMLList.new(hash).list
  ul = @htmldoc.at_xpath('//ul')
  ul.replace(@list)
end

Instance Method Details

#htmlObject



148
149
150
# File 'lib/twb/htmllistcollapsible.rb', line 148

def html
 " here's the @@doc"
end

#installNavImageFileObject



176
177
178
179
# File 'lib/twb/util/htmllistcollapsible.rb', line 176

def installNavImageFile
  navimage = File.dirname(__FILE__) + "/UpLeftArrowsNav.png"
  FileUtils.cp(navimage, Dir.pwd)
end

#title=(str) ⇒ Object



157
158
159
160
# File 'lib/twb/util/htmllistcollapsible.rb', line 157

def title=(str)
  title = @htmldoc.at_xpath('//div[@id="pgtitle"]')
  title.content = str if title 
end

#write(name = 'collapsibleList.html') ⇒ Object

Write the HTML to a file using the provided name.



167
168
169
170
171
172
173
174
# File 'lib/twb/util/htmllistcollapsible.rb', line 167

def write(name='collapsibleList.html')
  $f = File.open(name,'w')
  if $f
      $f.puts @htmldoc
      $f.close
  end
  installNavImageFile
end