From 72b084ccbefd9bf38c988cdbba5022a4602669b9 Mon Sep 17 00:00:00 2001 From: Chris Eppstein Date: Sat, 30 Jan 2010 16:20:03 -0800 Subject: [PATCH] Examples can now be targeted generally at a stylesheet instead of at only mixins. --- doc-src/README.markdown | 2 +- doc-src/layouts/partials/reference/examples.haml | 7 +++++++ doc-src/layouts/partials/reference/mixins.haml | 2 +- doc-src/layouts/reference.haml | 2 ++ doc-src/lib/stylesheets.rb | 12 ++++++++---- 5 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 doc-src/layouts/partials/reference/examples.haml diff --git a/doc-src/README.markdown b/doc-src/README.markdown index 5e0d493b..9bb2a25d 100644 --- a/doc-src/README.markdown +++ b/doc-src/README.markdown @@ -84,7 +84,7 @@ Example Metadata is used to associate the example to a mixin in the reference do mixin: awesome --- -After adding the example and adjusting the metadata, go to the reference page and you can verify that a link to the example has appeared. +After adding the example and adjusting the metadata, go to the reference page and you can verify that a link to the example has appeared. If the mixin property is omitted, then the example will be a general example for the stylesheet. ### How to Add New Reference Documentation diff --git a/doc-src/layouts/partials/reference/examples.haml b/doc-src/layouts/partials/reference/examples.haml new file mode 100644 index 00000000..e9d9421d --- /dev/null +++ b/doc-src/layouts/partials/reference/examples.haml @@ -0,0 +1,7 @@ +- if (examples = examples(@item)).any? + %h2 Examples + %dl.examples + - examples.each do |example| + %dt= link_to example.item[:title], example, :target => "_blank" + - if example.item[:description] + %dd= example.item[:description] diff --git a/doc-src/layouts/partials/reference/mixins.haml b/doc-src/layouts/partials/reference/mixins.haml index fd599c52..1769c8f0 100644 --- a/doc-src/layouts/partials/reference/mixins.haml +++ b/doc-src/layouts/partials/reference/mixins.haml @@ -8,7 +8,7 @@ .source-documentation = format_doc(mixin.comment) - - if (examples = mixin_examples(@item, mixin)).any? + - if (examples = examples(@item, mixin)).any? %dl.examples - examples.each do |example| %dt= link_to example.item[:title], example, :target => "_blank" diff --git a/doc-src/layouts/reference.haml b/doc-src/layouts/reference.haml index 386f9309..0e3445a8 100644 --- a/doc-src/layouts/reference.haml +++ b/doc-src/layouts/reference.haml @@ -4,6 +4,8 @@ = yield += render "partials/reference/examples" + = render "partials/reference/imports" = render "partials/reference/constants" diff --git a/doc-src/lib/stylesheets.rb b/doc-src/lib/stylesheets.rb index 723bed3b..4e48f3f2 100644 --- a/doc-src/lib/stylesheets.rb +++ b/doc-src/lib/stylesheets.rb @@ -140,10 +140,14 @@ def examples_for_item(item) end end -def mixin_examples(item, mixin) - examples_for_item(item).select do |i| - i[:mixin] == mixin.name - end.map{|i| i.reps.find{|r| r.name == :default}} +def examples(item, mixin = nil) + examples = examples_for_item(item) + if mixin + examples = examples.select {|i| i[:mixin] == mixin.name } + else + examples = examples.reject {|i| i[:mixin] } + end + examples.map{|i| i.reps.find{|r| r.name == :default}} end