@@ -88,7 +88,7 @@ def pages_for_group(group_name)
8888 #
8989 # A third section may optionally be provided to represent compiled CSS. If
9090 # it's not passed and `autogen_css` is `true`, it's generated from the SCSS
91- # source.
91+ # source. If the autogenerated CSS is empty, it's omitted entirely.
9292 #
9393 # If `syntax` is either `:sass` or `:scss`, the first section will be
9494 # interpreted as that syntax and the second will be interpreted (or
@@ -109,12 +109,18 @@ def example(autogen_css: true, syntax: nil, &block)
109109 sass_sections = sass ? sass . split ( "\n ---\n " ) . map ( &:strip ) : [ ]
110110
111111 if css . nil? && autogen_css
112- if scss_sections . length != 1
112+ sections = scss ? scss_sections : sass_sections
113+ if sections . length != 1
113114 throw ArgumentError . new (
114115 "Can't auto-generate CSS from more than one SCSS file." )
115116 end
116117
117- css = Sass ::Engine . new ( scss , syntax : :scss , style : :expanded ) . render
118+ css = Sass ::Engine . new (
119+ sections . first ,
120+ syntax : syntax || :scss ,
121+ style : :expanded
122+ ) . render
123+ css = nil if css . empty?
118124 end
119125 css_sections = css ? css . split ( "\n ---\n " ) . map ( &:strip ) : [ ]
120126
@@ -195,13 +201,16 @@ def example(autogen_css: true, syntax: nil, &block)
195201 if block_is_haml? ( block )
196202 haml_concat text
197203 else
198- concat text
204+ # Padrino's concat helper doesn't play nice with nested captures.
205+ @_out_buf << text
199206 end
200207 end
201208
202209 # Returns the number of lines of padding that's needed to match the height of
203210 # the `<pre>`s generated for `sections1` and `sections2`.
204211 def _total_padding ( sections1 , sections2 )
212+ sections1 ||= [ ]
213+ sections2 ||= [ ]
205214 [ sections1 , sections1 ] . map ( &:length ) . max . times . sum do |i |
206215 # Add 2 lines to each additional section: 1 for the extra padding, and 1
207216 # for the extra margin.
@@ -253,15 +262,27 @@ def release_url(impl)
253262 end
254263 end
255264
256- # Returns HTML for a note about the given implementation .
265+ # Returns HTML for a warning .
257266 #
258267 # The contents should be supplied as a block.
259- def impl_note
268+ def heads_up
260269 concat ( content_tag :aside , [
261270 content_tag ( :i , 'TODO(jina): style this div' ) ,
262- content_tag ( :strong , 'Implementation note: ' ) ,
271+ content_tag ( :strong , 'Heads up! ' ) ,
263272 _render_markdown ( capture { yield } )
264- ] , class : 'impl-note' )
273+ ] , class : 'warning' )
274+ end
275+
276+ # Returns HTML for a fun fact that's not directly relevant to the main
277+ # documentation.
278+ #
279+ # The contents should be supplied as a block.
280+ def fun_fact
281+ concat ( content_tag :aside , [
282+ content_tag ( :i , 'TODO(jina): style this div' ) ,
283+ content_tag ( :strong , 'Fun fact:' ) ,
284+ _render_markdown ( capture { yield } )
285+ ] , class : 'fun-fact' )
265286 end
266287
267288 # Renders a status dashboard for each implementation's support for a feature.
@@ -272,16 +293,27 @@ def impl_note
272293 # supporting the feature.
273294 #
274295 # When possible, prefer using the start version rather than `true`.
296+ #
297+ # This takes a Markdown block that should provide more information about the
298+ # implementation differences or the old behavior.
275299 def impl_status ( dart : nil , libsass : nil , ruby : nil )
276300 raise ArgumentError . new ( "Missing argument dart." ) if dart . nil?
277301 raise ArgumentError . new ( "Missing argument libsass." ) if libsass . nil?
278302 raise ArgumentError . new ( "Missing argument ruby." ) if ruby . nil?
279303
280- content_tag :table , [
304+ contents = [
281305 _impl_status_row ( 'Dart Sass' , dart ) ,
282306 _impl_status_row ( 'LibSass' , libsass ) ,
283307 _impl_status_row ( 'Ruby Sass' , ruby ) ,
284- ] , class : 'impl-status'
308+ ]
309+
310+ if block_given?
311+ contents . unshift ( content_tag ( :caption , [
312+ _render_markdown ( capture { yield } )
313+ ] ) )
314+ end
315+
316+ concat ( content_tag :table , contents , class : 'impl-status' )
285317 end
286318
287319 # Renders a single row for `impl_status`.
@@ -301,6 +333,34 @@ def _impl_status_row(name, status)
301333 ] , class : status ? 'supported' : 'unsupported'
302334 end
303335
336+ # Renders API docs for a Sass function.
337+ #
338+ # The function's name is parsed from the signature. The API description is
339+ # passed as a Markdown block. If `returns` is passed, it's included as the function's return type.
340+ def function ( signature , returns : nil )
341+ name = signature . split ( "(" ) . first
342+ html = Nokogiri ::HTML ( _render_markdown ( <<MARKDOWN ) )
343+ ```scss
344+ @function #{ signature }
345+ {}
346+ ```
347+ MARKDOWN
348+ highlighted_signature = html . css ( "pre code" ) . children .
349+ drop_while { |el | el . text != "@function" } .
350+ take_while { |el | el . text != "{}" } [ 1 ...-1 ] .
351+ map ( &:to_html ) . join . strip
352+
353+ concat ( content_tag :div , [
354+ content_tag ( :pre , [
355+ content_tag ( :code , highlighted_signature )
356+ ] , class : 'signature highlight scss' ) ,
357+
358+ returns ? content_tag ( :div , returns , class : 'return-type' ) : '' ,
359+
360+ _render_markdown ( capture { yield } )
361+ ] , class : 'function' , id : name )
362+ end
363+
304364 # A helper method that renders a chunk of Markdown text.
305365 def _render_markdown ( content )
306366 @redcarpet ||= Redcarpet ::Markdown . new (
0 commit comments