class JsDuck::Web::IndexHtml
Deals with creation of main HTML or PHP files.
Public Class Methods
new(assets, opts, paths={})
click to toggle source
# File lib/jsduck/web/index_html.rb, line 12 def initialize(assets, opts, paths={}) @assets = assets @opts = opts @paths = paths end
Public Instance Methods
write()
click to toggle source
In normal mode creates index.html.
When –seo enabled, creates index.php, template.html and print-template.html.
# File lib/jsduck/web/index_html.rb, line 21 def write if @opts.seo FileUtils.cp(@opts.template+"/index.php", @opts.output+"/index.php") create_template_html(@opts.template+"/template.html", @opts.output+"/template.html") create_print_template_html(@opts.template+"/print-template.html", @opts.output+"/print-template.html") create_index_template_html(@opts.template+"/index-template.html", @opts.output+"/index-template.html") else create_template_html(@opts.template+"/template.html", @opts.output+"/index.html") end end
Private Instance Methods
create_index_template_html(in_file, out_file)
click to toggle source
# File lib/jsduck/web/index_html.rb, line 60 def create_index_template_html(in_file, out_file) categories = @assets.categories.to_html guides = @assets.guides.to_html write_template(in_file, out_file, { "{title}" => @opts.title, "{header}" => header, "{categories}" => categories ? "<h1>API Documentation</h1> #{categories}" : "", "{guides}" => guides ? "<h1>Guides</h1> #{guides}" : "", "{css_path}" => File.basename(@paths[:css]), }) end
create_print_template_html(in_file, out_file)
click to toggle source
# File lib/jsduck/web/index_html.rb, line 52 def create_print_template_html(in_file, out_file) write_template(in_file, out_file, { "{title}" => @opts.title, "{header}" => header, "{css_path}" => File.basename(@paths[:css]), }) end
create_template_html(in_file, out_file)
click to toggle source
# File lib/jsduck/web/index_html.rb, line 34 def create_template_html(in_file, out_file) write_template(in_file, out_file, { "{title}" => @opts.title, "{mobile_redirect}" => @opts.seo ? include_script(@opts.template+"/mobile-redirect.js") : "", "{header}" => header, "{footer}" => footer, "{extjs_path}" => @opts.extjs_path, "{data_path}" => File.basename(@paths[:data]), "{css_path}" => File.basename(@paths[:css]), "{welcome}" => @assets.welcome.to_html("display:none"), "{categories}" => @assets.categories.to_html("display:none"), "{news}" => @assets.news.to_html("display:none"), "{guides}" => @assets.guides.to_html("display:none"), "{head_html}" => @opts.head_html, "{body_html}" => @opts.body_html, }) end
header()
click to toggle source
# File lib/jsduck/web/index_html.rb, line 77 def header @opts.title.sub(/^(.*?) +- +/, "<strong>\\1</strong> ") end
include_script(filename)
click to toggle source
# File lib/jsduck/web/index_html.rb, line 73 def include_script(filename) "<script type='text/javascript'>\n" + Util::IO.read(filename) + "\n</script>" end
write_template(in_file, out_file, replacements)
click to toggle source
Opens in_file, replaces {keys} inside it, writes to out_file
# File lib/jsduck/web/index_html.rb, line 93 def write_template(in_file, out_file, replacements) Logger.log("Writing", out_file) html = Util::IO.read(in_file) html.gsub!(/\{\w+\}/) do |key| replacements[key] ? replacements[key] : key end File.open(out_file, 'w') {|f| f.write(html) } end