Skip to content

Commit

Permalink
Add method entry builder.
Browse files Browse the repository at this point in the history
  • Loading branch information
Priit Haamer committed Sep 19, 2011
1 parent 551b1fd commit 03326cf
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
objects
.DS_Store
doc
pkg
40 changes: 36 additions & 4 deletions lib/rubydictionary/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ def generate(top_levels)

RDoc::TopLevel.all_classes.each do |clazz|
append_class_entry(clazz, xml)
clazz.method_list.each do |mthd|
append_method_entry(mthd, xml)
end
end
end
end
Expand All @@ -52,7 +55,7 @@ def append_class_entry(cls, xml)
xml.h1(cls.full_name, :xmlns => XMLNS)

xml.div(:xmlns => XMLNS) do
xml.cdata cls.description
xml << cls.description
end

# Link to class methods
Expand Down Expand Up @@ -81,19 +84,48 @@ def append_class_entry(cls, xml)
end
end

# <d:entry id="method_method_id" d:title="method-Name">
# <d:index d:value="method full name"/>
# <d:index d:value="method name"/>
# <h1><a href="x-dictionary:r:class_id:org.ruby-lang.Dictionary">class full name</a> <span class="methodtype"> <%= @method.singleton ? '::' : '#' %> </span> <%= @method.name.escape %> <span class="visibility">(<%= @method.visibility %>)</span></h1>
# <% unless @method.arglists.nil? %><p class="signatures"><%= @method.arglists.escape %></p><% end %>
# <% unless !@method.respond_to?(:aliases) || @method.aliases.empty? %><p>Aliases: <%= @method.aliases.map {|a| a.new_name }.join(", ").escape %></p><% end %>
# <% unless !@method.respond_to?(:is_alias_for) || @method.is_alias_for.nil? %><p>Alias for: <%= @method.is_alias_for.escape %></p><% end %>
# <% unless @description.empty? %>
# <%= @description %>
# <% end %>
# </d:entry>
def append_method_entry(mthd, xml)
xml.entry('id' => method_id(mthd), 'd:title' => method_title(mthd)) do
xml.index('d:value' => mthd.full_name)

xml.h1(mthd.full_name, :xmlns => XMLNS)

xml.div(:xmlns => XMLNS) do
xml << mthd.description
end
end
end

def class_id(cls)
cls.full_name.downcase.gsub('::', '_')
'class_' << cls.object_id.to_s(36)
end

def class_title(cls)
cls.full_name
end

def method_title(mthd)
# TODO: escape <>
mthd.name
end

def method_url(mthd)
"x-dictionary:r:method_#{method_id(mthd)}:org.ruby-lang.Dictionary"
# TODO: org.ruby-lang.Dictionary is a bundle identifier defined in .plist file
"x-dictionary:r:#{method_id(mthd)}:org.ruby-lang.Dictionary"
end

def method_id(mthd)
mthd.name
'method_' << mthd.object_id.to_s(36)
end
end

0 comments on commit 03326cf

Please sign in to comment.