Commit 790cae70 authored by Rene Saarsoo's avatar Rene Saarsoo
Browse files

Add Tag#css attribute for injecting additional CSS.

For now the CSS just gets added to index.html file, next step would
be to move it into a separate file.
parent 654569c4
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ module JsDuck
        "{guides}" => @assets.guides.to_html("display:none"),
        "{head_html}" => @opts.head_html,
        "{body_html}" => @opts.body_html,
        "{head_css}" => TagRegistry.css,
      })
    end

@@ -47,6 +48,7 @@ module JsDuck
      write_template(in_file, out_file, {
        "{title}" => @opts.title,
        "{header}" => @opts.header,
        "{head_css}" => TagRegistry.css,
      })
    end

@@ -59,6 +61,7 @@ module JsDuck
        "{header}" => @opts.header,
        "{categories}" => categories ? "<h1>API Documentation</h1> #{categories}" : "",
        "{guides}" => guides ? "<h1>Guides</h1> #{guides}" : "",
        "{head_css}" => TagRegistry.css,
      })
    end

+7 −0
Original line number Diff line number Diff line
@@ -189,6 +189,13 @@ module JsDuck::Tag
    def to_html(context)
    end

    # A string of CSS to add to the builtin CSS of the generated docs.
    # For example, to style a signature label:
    #
    #     @css = ".signature .mytag { color: red }"
    #
    attr_reader :css

    # Returns all descendants of JsDuck::Tag::Tag class.
    def self.descendants
      result = []
+10 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ module JsDuck
      @html_renderers = []
      @html_renderers_sorted = false
      @member_types = []
      @css = []

      @loader = TagLoader.new
      load_from(File.dirname(__FILE__) + "/tag")
@@ -65,6 +66,10 @@ module JsDuck
        if tag.html_position
          @html_renderers << tag
        end

        if tag.css
          @css << tag.css
        end
      end
    end

@@ -132,6 +137,11 @@ module JsDuck
      @html_renderers
    end

    # Returns all the CSS gathered from @css attributes of tags.
    def css
      @css.join("\n")
    end

    #
    # Accessors for a single tag
    #
+1 −0
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@
  <link rel="stylesheet" href="resources/codemirror/codemirror.css" type="text/css" />
  <link rel="stylesheet" href="resources/prettify/prettify.css" type="text/css" />
  <!-- END CSS -->
  <style type="text/css">{head_css}</style>

</head>
<body style="background: #fff; min-width: 0;">
+1 −0
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@
  <style type="text/css">
  .description .short { display: none !important }
  .description .long { display: block !important }
  {head_css}
  </style>
  <title>{subtitle} - {title}</title>
</head>
Loading