lib/view.rb in inqlude-0.7.0 vs lib/view.rb in inqlude-0.7.1

- old
+ new

@@ -34,10 +34,13 @@ system "cp #{view_dir}/public/* #{output_dir}/public/" assert_dir "#{output_dir}/schema" system "cp #{schema_dir}/* #{output_dir}/schema" + create_inqlude_all(output_dir) + + @root = "" render_template "index", output_dir render_template "development", output_dir render_template "unreleased", output_dir @@ -70,10 +73,16 @@ file_name = "libraries/" + library.name render_template "library", output_dir, file_name end end + def create_inqlude_all(output_dir) + File.open(File.join(output_dir, "inqlude-all.json"), "w") do |f| + f.write(@manifest_handler.generate_inqlude_all) + end + end + def render_template name, output_dir, file_name = nil layout = template "layout" layout_engine = Haml::Engine.new layout page = template name @@ -97,16 +106,12 @@ def style_sheet "<link href='#{@root}public/inqlude.css' rel='stylesheet' type='text/css' />" end - def m attr, subattr = nil - if subattr - @manifest[ attr ][ subattr ] - else - @manifest[ attr ] - end + def m + @manifest end def link_to_manifest name "<a href=\"#{@root}libraries/#{name}.html\">#{name}</a>" end @@ -121,11 +126,11 @@ end "<a href=\"#{url}\">#{title}</a>" end def list_attribute attribute - attr = m attribute + attr = @manifest.send(attribute) return "" if !attr || attr.size == 0 # We assume attribute is plural formed by adding an 's' label = attribute.capitalize @@ -149,17 +154,17 @@ out += "</div>" out end def version_content - if @manifest["schema_type"] == "generic" - raise "Can't get version for generic manifest '#{@manifest["name"]}'" + if @manifest.class == ManifestGeneric + raise InqludeError.new("Can't get version for generic manifest '#{@manifest.name}'") end - out = @manifest["version"] - out += " (#{@manifest["maturity"]})" + out = @manifest.version + out += " (#{@manifest.maturity})" out += "<span class='release-date'>" - out += "released on #{@manifest["release_date"]}" + out += "released on #{@manifest.release_date}" out += "</span>" if !old_versions.empty? out += "<span class='old-versions'>" out += "(older versions: #{old_versions.join(", ")})" out += "</span>" @@ -177,35 +182,32 @@ return email end end def link_item key, label - if m( "urls", key ) + if m.urls.send(key) out = "<li><a href=\"" - out += m( "urls", key ) - out += "\">#{label}</a>" + out += m.urls.send(key) + out += "\">#{label}</a></li>" return out else return "" end end def custom_urls out = "" - urls = m "urls", "custom" + urls = @manifest.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 maturity = nil - if @manifest_handler.libraries(maturity).empty? - @manifest_handler.read_remote - end @manifest_handler.libraries(maturity) end def unreleased_libraries @manifest_handler.unreleased_libraries @@ -229,33 +231,34 @@ 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" + @manifest.urls.class.all_keys.each do |key, type| + if key != :homepage && key != :screenshots && key != :logo && + key != :description_source + if @manifest.urls.send(key) 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 += @manifest.name + url += "/#{@manifest.name}.#{@manifest.release_date}.manifest" url end def old_versions - versions = @library.versions.reject{ |v| v == @manifest["version"] } + versions = @library.versions.reject{ |v| v == @manifest.version } versions.reverse end def render_description - doc = Kramdown::Document.new(@manifest["description"]) + doc = Kramdown::Document.new(@manifest.description) doc.to_html end private