WebRI  WebRI::GeneratorOne

[Validate]
Generated with WebRI Redfish 1.2

GeneratorOne

This is the static website generator which creates a single page.

Attributes

output[R]

Dir in which to store generated html

html[R]

Public Class Methods

new(service, options={}) click to toggle source
# File lib/webri/server/generator1.rb, line 23
    def initialize(service, options={})
      super(service, options)

      @html = ""

      #@cgi = {} #CGI.new('html4')
      #@service = service
      @directory_depth = 0
    end

Public Instance Methods

asset(name) click to toggle source
# File lib/webri/server/generator1.rb, line 189
    def asset(name)
      @assets[name] ||= File.read(File.join(directory, 'assets', name))
    end
css() click to toggle source
# File lib/webri/server/generator1.rb, line 194
    def css
      asset('css/style1.css')
    end
current_content() click to toggle source
# File lib/webri/server/generator1.rb, line 184
    def current_content
      @current_content
    end
generate(output=".") click to toggle source

generate webpages

# File lib/webri/server/generator1.rb, line 71
    def generate(output=".")
      @output = File.expand_path(output)
      @assets = {}
      # traverse the the hierarchy

      #generate_recurse(heirarchy)

#      heirarchy.class_methods.each do |name|
#        p name
#      end

#      heirarchy.instance_methods.each do |name|
#        p name
#      end

      heirarchy.subspaces.each do |name, entry|
        #p name, entry
        generate_recurse(entry)
      end

      generate_support_files
    end
generate_recurse(entry) click to toggle source
# File lib/webri/server/generator1.rb, line 95
    def generate_recurse(entry)
      keyword = entry.full_name

      if keyword
        puts keyword
        @current_content = service.info(keyword) #lookup(keyword)
      else
        keyword = ''
        @current_content = "Welcome"
      end

      file = entry.file_name
      #file = File.join(output, file)

      #file = keyword
      #file = file.gsub('::', '--')
      #file = file.gsub('.' , '--')
      #file = file.gsub('#' , '-')
      #file = File.join(output, file + '.html')

      html << %[<h1>#{entry.full_name}</h1>]

      html << %[\n<div id="#{file}" class="slot module">\n]
      html << service.info(keyword)
      html << %[\n</div>\n]

      #html << %[<h1>Class Methods</h1>]
      cmethods = entry.class_methods.map{ |x| x.to_s }.sort
      cmethods.each do |name|
        mname = "#{entry.full_name}.#{name}"
        mfile = WebRI.entry_to_path(mname)
        #mfile = File.join(output, mfile)
        #mfile = File.join(output, "#{entry.file_name}/c-#{esc(name)}.html")
        html << %[\n<div id="#{mfile}" name="#{mfile}" class="slot cmethod">\n]
        html << service.info(mname)
        html << %[\n</div>\n]
        #write(mfile, service.info(mname))
      end

      #html << %[<h1>Instance Methods</h1>]
      imethods = entry.instance_methods.map{ |x| x.to_s }.sort
      imethods.each do |name|
        mname = "#{entry.full_name}##{name}"
        mfile = WebRI.entry_to_path(mname)
        #mfile = File.join(output, mfile)
        #mfile = File.join(output, "#{entry.file_name}/i-#{esc(name)}.html")
        html << %[\n<div id="#{mfile}" name="#{mfile}" class="slot imethod">\n]
        html << service.info(mname)
        html << %[\n</div>\n]
        #write(mfile, service.info(mname))
      end

      entry.subspaces.each do |child_name, child_entry|
        next if child_entry == entry
        @directory_depth += 1
        generate_recurse(child_entry)
        @directory_depth -= 1
      end
    end
generate_support_files() click to toggle source
# File lib/webri/server/generator1.rb, line 163
    def generate_support_files
      FileUtils.mkdir_p(output)

      index = render(template('index1'))

      #base = base.strip.chomp('</html>').strip.chomp('</body>').strip.chomp('</div>')
      #base = base + html
      #base = base + "</div>\n</body>\n</html>"

      write(File.join(output, 'webri.html'), index)

      #write(File.join(output, 'header.html'), page_header)
      #write(File.join(output, 'tree.html'),   page_tree)
      #write(File.join(output, 'main.html'),   page_main)

      # copy assets
      #dir = File.join(directory, 'assets')
      #FileUtils.cp_r(dir, output)
    end
jquery() click to toggle source
# File lib/webri/server/generator1.rb, line 199
    def jquery
      '' #  asset('js/jquery.js')
    end
rijquery() click to toggle source
# File lib/webri/server/generator1.rb, line 204
    def rijquery
      '' #asset('js/ri.jquery.js')
    end
write(file, text) click to toggle source
# File lib/webri/server/generator1.rb, line 156
    def write(file, text)
      puts file
      FileUtils.mkdir_p(File.dirname(file))
      File.open(file, 'w') { |f| f << text.to_s }
    end

Disabled; run with --debug to generate this.