Examples can now be targeted generally at a stylesheet instead of at

only mixins.
This commit is contained in:
Chris Eppstein 2010-01-30 16:20:03 -08:00
parent 41183a2f85
commit 72b084ccbe
5 changed files with 19 additions and 6 deletions

View File

@ -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

View File

@ -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]

View File

@ -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"

View File

@ -4,6 +4,8 @@
= yield
= render "partials/reference/examples"
= render "partials/reference/imports"
= render "partials/reference/constants"

View File

@ -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