lib/view.rb in inqlude-0.8.0 vs lib/view.rb in inqlude-0.9.0

- old
+ new

@@ -14,46 +14,44 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. class View - attr_accessor :enable_disqus,:enable_search,:manifest,:library,:group_name + attr_accessor :enable_disqus,:enable_search,:manifest,:library,:group_name,:templates attr_reader :root def initialize handler @manifest_handler = handler end def create output_dir - puts "Creating web site in '#{output_dir}' from '#{@manifest_handler.settings.manifest_path}'" - assert_dir output_dir system "cp #{view_dir}/favicon.ico #{output_dir}" + + if templates == "two-column" + system "cp #{view_dir}/ios.ico #{output_dir}" + end assert_dir "#{output_dir}/public" 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 - render_template "commercial", output_dir - render_template "all", output_dir - render_template "about", output_dir - render_template "get", output_dir - render_template "contribute", output_dir - render_template "search", output_dir - + Dir.glob("#{view_dir}*.html.haml") do |file| + template_name = (File.basename file).split(".").first + if !["layout","group","library"].include? template_name + render_template template_name, output_dir + end + end + groups_path = "#{output_dir}/groups/" assert_dir groups_path @root = "../" @@ -71,18 +69,35 @@ @library = library @manifest = library.latest_manifest file_name = "libraries/" + library.name render_template "library", output_dir, file_name end + + if templates == 'two-column' + topics_path = "#{output_dir}/topics/" + assert_dir topics_path + + @root = "../" + + topics.each do |topic| + @topic = topic + file_name = "topics/" + topic + render_template "topic", output_dir, file_name + end + 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 template_directory_exists? + File.directory?(view_dir) ? true : false + end + def render_template name, output_dir, file_name = nil layout = template "layout" layout_engine = Haml::Engine.new layout page = template name @@ -110,14 +125,22 @@ def m @manifest end + def t + @topic + end + def link_to_manifest name "<a href=\"#{@root}libraries/#{name}.html\">#{name}</a>" end + def link_to_library name, display_name + "<a href=\"#{@root}libraries/#{name}.html\">#{display_name}</a>" + end + def link url "<a href=\"#{url}\" target=\"_blank\">#{url}</a>" end def link_to title, url @@ -125,10 +148,18 @@ url = "#{@root}#{url}.html" end "<a href=\"#{url}\">#{title}</a>" end + def link_to_group name, display_name + "<a href=\"#{@root}groups/#{name}.html\">#{display_name}</a>" + end + + def link_to_topic name + "<a href=\"#{@root}topics/#{name}.html\">#{name}</a>" + end + def list_attribute attribute attr = @manifest.send(attribute) return "" if !attr || attr.size == 0 # We assume attribute is plural formed by adding an 's' @@ -215,20 +246,32 @@ def commercial_libraries @manifest_handler.commercial_libraries end + def latest_libraries + @manifest_handler.latest_libraries + end + def group_title if @group_name == "kde-frameworks" return "KDE Frameworks" end "" end def group @manifest_handler.group(@group_name) end + + def topic name + @manifest_handler.topic(name) + end + + def no_of_libraries topic + @manifest_handler.no_of_libraries(topic) + end def disqus_enabled? @enable_disqus end @@ -259,10 +302,14 @@ def render_description doc = Kramdown::Document.new(@manifest.description) doc.to_html end + def topics + ['API', 'Artwork', 'Bindings', 'Communication', 'Data', 'Desktop', 'Development', 'Graphics', 'Logging', 'Mobile', 'Multimedia', 'Printing', 'QML', 'Scripting', 'Security', 'Text', 'Web', 'Widgets'] + end + private def assert_dir name Dir::mkdir name unless File.exists? name end @@ -270,10 +317,10 @@ def template name File.read( view_dir + "#{name}.html.haml" ) end def view_dir - File.expand_path( File.dirname( __FILE__ ) + "/../view/" ) + "/" + File.expand_path( File.dirname( __FILE__ ) + "/../view/#{templates}" ) + "/" end def schema_dir File.expand_path( File.dirname( __FILE__ ) + "/../schema/" ) + "/" end