Commit fbfb7ddd authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Save CSS from tags into separate CSS file.

MD5-rename the file like with data.js file.
Then link it from index.html.

Also reorganize the Web::Writer class.
Save the MD5-renamed files to a local hash instead of
polluting the Options object - then pass the hash directly
to IndexHtml writer.
parent ebf0c3d4
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -46,7 +46,6 @@ module JsDuck
    attr_accessor :template_dir
    attr_accessor :template_links
    attr_accessor :extjs_path
    attr_accessor :data_path
    attr_accessor :local_storage_db
    attr_accessor :touch_examples_ui
    attr_accessor :ext_namespaces
@@ -125,7 +124,6 @@ module JsDuck
      @template_dir = @root_dir + "/template-min"
      @template_links = false
      @extjs_path = "extjs/ext-all.js"
      @data_path = nil # This gets assigned in JsDuck::WebWriter after writing the data file.
      @local_storage_db = "docs"
      @touch_examples_ui = false
      @imports = []

lib/jsduck/web/css.rb

0 → 100644
+18 −0
Original line number Diff line number Diff line
require 'jsduck/tag_registry'
require 'jsduck/util/md5'

module JsDuck
  module Web

    # Writes the CSS gathered from Tag classes into given file.
    # Then Renames the file so it contains an MD5 hash inside it,
    # returning the resulting fingerprinted name.
    class Css
      def write(filename)
        File.open(filename, 'w') {|f| f.write(TagRegistry.css) }
        Util::MD5.rename(filename)
      end
    end

  end
end
+7 −1
Original line number Diff line number Diff line
require 'jsduck/util/json'
require 'jsduck/util/md5'
require 'jsduck/web/icons'
require 'jsduck/web/search'
require 'jsduck/tag_registry'
@@ -14,7 +15,9 @@ module JsDuck
        @opts = opts
      end

      # Writes classes, guides, videos, and search data to one big .js file
      # Writes classes, guides, videos, and search data to one big .js file.
      # Then Renames the file so it contains an MD5 hash inside it,
      # returning the resulting fingerprinted name.
      def write(filename)
        js = "Docs = " + Util::Json.generate({
          :data => {
@@ -34,7 +37,10 @@ module JsDuck
            :commentsDomain => @opts.comments_domain,
          }
        }) + ";\n"

        File.open(filename, 'w') {|f| f.write(js) }

        Util::MD5.rename(filename)
      end

    end
+6 −5
Original line number Diff line number Diff line
@@ -8,9 +8,10 @@ module JsDuck

    # Deals with creation of main HTML or PHP files.
    class IndexHtml
      def initialize(assets, opts)
      def initialize(assets, opts, paths={})
        @assets = assets
        @opts = opts
        @paths = paths
      end

      # In normal mode creates index.html.
@@ -36,13 +37,13 @@ module JsDuck
          "{header}" => @opts.header,
          "{footer}" => "<div id='footer-content' style='display: none'>#{@opts.footer}</div>",
          "{extjs_path}" => @opts.extjs_path,
          "{data_path}" => File.basename(@opts.data_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"),
          "{guides}" => @assets.guides.to_html("display:none"),
          "{head_html}" => @opts.head_html,
          "{body_html}" => @opts.body_html,
          "{head_css}" => TagRegistry.css,
        })
      end

@@ -50,7 +51,7 @@ module JsDuck
        write_template(in_file, out_file, {
          "{title}" => @opts.title,
          "{header}" => @opts.header,
          "{head_css}" => TagRegistry.css,
          "{css_path}" => File.basename(@paths[:css]),
        })
      end

@@ -63,7 +64,7 @@ module JsDuck
          "{header}" => @opts.header,
          "{categories}" => categories ? "<h1>API Documentation</h1> #{categories}" : "",
          "{guides}" => guides ? "<h1>Guides</h1> #{guides}" : "",
          "{head_css}" => TagRegistry.css,
          "{css_path}" => File.basename(@paths[:css]),
        })
      end

+18 −23
Original line number Diff line number Diff line
require 'jsduck/exporter/app'
require 'jsduck/format/batch'
require 'jsduck/util/md5'
require 'jsduck/class_writer'
require 'jsduck/inline_examples'
require 'jsduck/web/template'
require 'jsduck/web/index_html'
require 'jsduck/web/data'
require 'jsduck/web/css'
require 'jsduck/web/source'
require 'fileutils'

@@ -22,11 +22,9 @@ module JsDuck
      end

      def write
        clean_output_dir

        write_template_files
        write_app_data
        write_index_html

        write_html_files

        # class-formatting is done in parallel which breaks the links
        # between source files and classes. Therefore it MUST to be done
@@ -41,19 +39,22 @@ module JsDuck
        @assets.write
      end

      # Clean output dir and copy over template files
      def write_template_files
        FileUtils.rm_rf(@opts.output_dir)
        Web::Template.new(@opts).write
      end

      def write_app_data
        filename = @opts.output_dir+"/data.js"
        Web::Data.new(@relations, @assets, @opts).write(filename)
        # Rename the file and remember the name for use in IndexHtml.write
        @opts.data_path = Util::MD5.rename(filename)
      end
      # Generate data.js and styles.css.
      # Then generate HTML files, linking to the data.js and styles.css from them.
      def write_html_files
        # Remember the MD5-fingerprinted filenames
        paths = {
          :data => Web::Data.new(@relations, @assets, @opts).write(@opts.output_dir+"/data.js"),
          :css => Web::Css.new.write(@opts.output_dir+"/styles.css"),
        }

      def write_index_html
        Web::IndexHtml.new(@assets, @opts).write
        Web::IndexHtml.new(@assets, @opts, paths).write
      end

      def write_source
@@ -61,6 +62,10 @@ module JsDuck
        source_writer.write(@opts.output_dir + "/source")
      end

      def format_classes
        Format::Batch.format_all!(@relations, @assets, @opts)
      end

      def write_inline_examples
        examples = InlineExamples.new
        examples.add_classes(@relations)
@@ -73,16 +78,6 @@ module JsDuck
        class_writer.write(@opts.output_dir+"/output", ".js")
      end

      # -- util routines --

      def clean_output_dir
        FileUtils.rm_rf(@opts.output_dir)
      end

      def format_classes
        Format::Batch.format_all!(@relations, @assets, @opts)
      end

    end

  end
Loading