lib/view.rb in inqlude-0.0.5 vs lib/view.rb in inqlude-0.0.6

- old
+ new

@@ -15,11 +15,13 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. class View attr_accessor :enable_disqus - + attr_accessor :enable_search + attr_reader :root + def initialize handler @manifest_handler = handler end def create output_dir @@ -32,19 +34,21 @@ render_template "index", output_dir render_template "about", output_dir render_template "get", output_dir render_template "contribute", output_dir + render_template "search", output_dir library_path = "#{output_dir}/libraries/" assert_dir library_path @root = "../" - manifests.each do |manifest| - @manifest = manifest - file_name = "libraries/" + manifest["name"] + @manifest_handler.libraries.each do |library| + @library = library + @manifest = library.manifests.last + file_name = "libraries/" + library.name render_template "library", output_dir, file_name end end def render_template name, output_dir, file_name = nil @@ -72,12 +76,16 @@ def style_sheet "<link href='#{@root}public/inqlude.css' rel='stylesheet' type='text/css' />" end - def m attr - @manifest[ attr ] + def m attr, subattr = nil + if subattr + @manifest[ attr ][ subattr ] + else + @manifest[ attr ] + end end def link_to_manifest name "<a href=\"libraries/#{name}.html\">#{name}</a>" end @@ -91,18 +99,102 @@ url = "#{@root}#{url}.html" end "<a href=\"#{url}\">#{title}</a>" end - def manifests - if @manifest_handler.manifests.empty? + def list_attribute attribute + attr = m attribute + return "" if !attr || attr.size == 0 + + # We assume attribute is plural formed by adding an 's' + + label = attribute.capitalize + + entries = Array.new + attr.each do |a| + entries.push markup_email( a ) + end + + out = "<p>" + if attr.size > 1 + out += label + ": " + entries.join(", ") + else + out += label[0..-2] + ": " + entries.first + end + out += "</p>" + + out + end + + def markup_email email + if email =~ /(.*) <(.*)>/ + name = $1 + email = $2 + + return "<a href=\"mailto:#{email}\">#{name}</a>" + else + return email + end + end + + def link_item key, label + if m( "urls", key ) + out = "<li><a href=\"" + out += m( "urls", key ) + out += "\">#{label}</a>" + return out + else + return "" + end + end + + def custom_urls + out = "" + urls = m "urls", "custom" + if urls && !urls.empty? + urls.each do |text,url| + out += "<li><a href=\"#{url}\">#{text}</a></li>" + end + end + out + end + + def libraries + if @manifest_handler.libraries.empty? @manifest_handler.read_remote end - @manifest_handler.manifests + @manifest_handler.libraries end def disqus_enabled? @enable_disqus + end + + def more_urls? + if @manifest["urls"] + @manifest["urls"].each do |name,url| + if name != "homepage" && name != "screenshots" && name != "logo" && name != "description_source" + return true + end + end + end + return false + end + + def editor_url + url = "https://github.com/cornelius/inqlude-data/blob/master/" + url += @manifest["name"] + url += "/#{@manifest["name"]}.#{@manifest["release_date"]}.manifest" + url + end + + def old_versions + versions = Array.new + count = @library.manifests.count + if count > 1 + versions = @library.manifests[0..count-2].map {|m| m["version"] } + end + versions.reverse end private def assert_dir name