Extract a mixin partial.

This commit is contained in:
Chris Eppstein 2010-01-23 19:47:28 -08:00
parent c05807ce31
commit 769e9c0c8e
5 changed files with 50 additions and 17 deletions

View File

@ -8,19 +8,4 @@
= render "partials/reference/imports"
%h2 Mixins
- mixins(@item).each do |mixin|
%a.view-source{:href=>"#", :onclick => "$('#mixin-source-#{mixin.name}').dialog('open'); return false;"} View Source
%h3.mixin{:id=>"mixin-#{mixin.name}"}
%a.permalink{:href => "#mixin-#{mixin.name}"}= mixin_signature mixin
.source-documentation= format_doc(mixin.comment)
- render 'dialog', :title => "Source for +#{mixin.name}", :id => "mixin-source-#{mixin.name}" do
%pre.source-code.sass= mixin.to_sass
- content_for :footer do
:javascript
$(function(){
$('.ui-dialog').dialog({hide: true, modal: true, autoOpen: false, width: 400});
});
= render "partials/reference/mixins"

View File

@ -1 +1 @@
.ui-dialog{:style => "display: none;", :id => @id, :title => @title}= yield
.ui-dialog{(@html || {}).merge(:style => "display: none;")}= yield

View File

@ -0,0 +1,16 @@
- if (mixin_defs = mixins(@item)).any?
%h2 Mixins
- mixin_defs.each do |mixin|
%a.view-source{:href=>"#", :onclick => "$('#mixin-source-#{mixin.name}').dialog('open'); return false;"} View Source
%h3.mixin{:id=>"mixin-#{mixin.name}"}
%a.permalink{:href => "#mixin-#{mixin.name}"}= mixin_signature mixin
.source-documentation= format_doc(mixin.comment)
= mixin_source_dialog(mixin) do
%pre.source-code.sass= mixin.to_sass
:javascript
$(function(){
$('.ui-dialog.mixin').dialog({hide: true, modal: true, autoOpen: false, width: 400});
});

View File

@ -0,0 +1 @@
--- {}

View File

@ -48,10 +48,41 @@ def mixins(item)
mixins
end
def constants(item)
sass_tree = tree(item)
constants = []
comment = nil
sass_tree.children.each do |child|
if child.is_a?(Sass::Tree::VariableNode)
child.comment = comment
comment = nil
constants << child
elsif child.is_a?(Sass::Tree::CommentNode)
comment ||= ""
comment << "\n" unless comment.empty?
comment << child.docstring
else
comment = nil
end
end
constants
end
def mixin_signature(mixin)
mixin.sass_signature(:include)
end
def mixin_source_dialog(mixin, &block)
vars = {
:html => {
:id => "mixin-source-#{mixin.name}",
:class => "mixin",
:title => "Source for +#{mixin.name}"
}
}
render 'dialog', vars, &block
end
def format_doc(docstring)
RDiscount.new(docstring).to_html
end