class BookmarkPage

Attributes

bookmarks[RW]
css[RW]
data[RW]
js[RW]

Public Class Methods

new(params = {}) click to toggle source
# File lib/bookmark_page.rb, line 9
def initialize(params = {})
  params.each { |key, value| instance_variable_set("@#{key}", value) }
  if params[:file]
    read params[:file]
  else
    read 'bookmarks.html'
  end
  if params[:assets_dir]
    load_assets params[:assets_dir]
  else
    load_assets '.'
  end
  @bookmarks = []
  @folder_class ||= 'folder'
  @folder_head_class ||= 'folder-head'
  @link_class ||= 'link'
end

Public Instance Methods

load_assets(assets_dir) click to toggle source
# File lib/bookmark_page.rb, line 34
def load_assets(assets_dir)
  raise "Dir not found: #{assets_dir}" unless File.directory? assets_dir
  @css = Dir.glob "#{assets_dir}/**/*.css"
  @js = Dir.glob "#{assets_dir}/**/*.js"
end
parse() click to toggle source
# File lib/bookmark_page.rb, line 40
def parse
  depth = 0
  @data_lines.each do |l|
    if l.include?('<DT>')
      if l.include? 'HREF'
        @bookmarks << [get_link_href(l), get_tag_content(l), get_icon_data(l)]
      else
        @bookmarks << ['HEADING', depth, get_tag_content(l)]
      end
    end
    if l.include?('<DL>')
      @bookmarks << 'UL'
      depth += 1
    end
    if l.include?('</DL>')
      @bookmarks << '/UL'
      depth -= 1
    end
  end
  template_file = File.open('lib/out.html.erb', 'rb')
  template = template_file.read
  renderer = ERB.new(template)
  renderer.result(binding)
end
read(filename) click to toggle source
# File lib/bookmark_page.rb, line 27
def read(filename)
  raise "File not found: #{filename}" unless File.exist?(filename)
  f = File.open(filename, 'rb')
  @data = f.read
  @data_lines = @data.split("\n")
end