Author: sebb
Date: Wed Apr 25 01:17:23 2018
New Revision: 1830041

URL: http://svn.apache.org/viewvc?rev=1830041&view=rev
Log:
Simplify template and add docs

Modified:
    attic/site-jekyll/README.md
    attic/site-jekyll/src/_layouts/project.html
    attic/site-jekyll/src/_plugins/generate_projects.rb

Modified: attic/site-jekyll/README.md
URL: 
http://svn.apache.org/viewvc/attic/site-jekyll/README.md?rev=1830041&r1=1830040&r2=1830041&view=diff
==============================================================================
--- attic/site-jekyll/README.md (original)
+++ attic/site-jekyll/README.md Wed Apr 25 01:17:23 2018
@@ -23,4 +23,29 @@ README.md - this file
 Adding a new project
 ====================
 Add a new object to src/_data/projects.json and fill in the details
-There is a sample object in src/_data/projects.txt
\ No newline at end of file
+There is a sample object in src/_data/projects.txt
+
+How the build works
+===================
+The build runs Jekyll, e.g.
+jekyll build --source "src" --destination "docs"
+This first empties the docs/ directory, and then processes the files under src/
+Files under the src/ directories starting with an underscore are not copied 
across,
+but all other files and directories are copied to docs/
+
+If the file has the extension .html (or some others) it will be processed by 
Jekyll
+which looks for embedded markers of the form
+{{ command to generate output }}
+or
+{% control-flow %}
+
+Note that there is no src/projects directory.
+Instead, there is a Ruby script plugin called src/_plugins/generate_projects.rb
+This is processed on startup, and reads the src/_data/projects.json file
+For each object, it creates a project page object which it passes back to 
Jekyll
+This page object uses the template src/_layouts/project.html.
+Jekyll processes each page using the data that has been set up.
+
+The Ruby script is also used to pre-process some of the raw JSON data into a 
form
+that is easier to use in the template. Although the templating language is 
quite
+powerful, it's generally easier to use Ruby to generate the variable.

Modified: attic/site-jekyll/src/_layouts/project.html
URL: 
http://svn.apache.org/viewvc/attic/site-jekyll/src/_layouts/project.html?rev=1830041&r1=1830040&r2=1830041&view=diff
==============================================================================
--- attic/site-jekyll/src/_layouts/project.html (original)
+++ attic/site-jekyll/src/_layouts/project.html Wed Apr 25 01:17:23 2018
@@ -50,6 +50,30 @@
                <div class="column span-15 colborder">
                             
 <div class="section-content">
+{%- comment %}
+
+Variables used by the template (page.json.*):
+description
+dist
+full_dash
+issueURL
+issueType
+mailnames
+name
+nodist
+nokeys
+postlude
+project
+retired
+scmName
+scmType
+scmURL
+subproject
+website
+wiki
+wikiname
+
+{%- endcomment %}
 <p><a href="{{ page.json.website }}">Apache {{ page.json.name }}</a> moved 
into the Attic in {{ page.json.retired }}. 
 {{ page.json.description }}</p>
 
@@ -78,15 +102,10 @@
       </td>
 {%- endif %}
     </tr>
-{%- if page.json.bugzilla %}
-    <tr>
-      <td>Issue Tracker</td>
-      <td><a href="https://bz.apache.org/bugzilla/buglist.cgi?product={{ 
page.json.bugzilla }}">Bugzilla</a></td>
-    </tr>
-{%- elsif page.json.jira %}
+{%- if page.json.issueURL %}
     <tr>
       <td>Issue Tracker</td>
-      <td><a href="https://issues.apache.org/jira/browse/{{ page.json.jira 
}}/">JIRA</a></td>
+      <td><a href="{{ page.json.issueURL }}">{{ page.json.issueType }}</a></td>
     </tr>
 {%- endif %}
 {%- if page.json.wiki %}
@@ -95,21 +114,10 @@
       <td><a href="{{ page.json.wiki }}">{{ page.json.wikiname }}</a></td>
     </tr>
 {%- endif %}
-{%- if page.json.scm == 'svn' %}
-    <tr>
-      <td>Source Code (Subversion)</td>
-      <td><a href="http://svn.apache.org/viewvc/{{ page.json.project }}/{{ 
page.json.subproject }}">svn.apache.org/repos/asf/{{ page.json.project }}/{{ 
page.json.subproject }}</a></td>
-    </tr>
-{%- elsif page.json.scm == 'git-wip' %}
-    <tr>
-      <td>Source Code (Git)</td>
-      <td><a href="https://git-wip-us.apache.org/repos/asf?p={{ 
page.json.project }}.git">git-wip-us.apache.org/repos/asf?p={{ 
page.json.project }}.git</a></td>
-    </tr>
-{%- elsif page.json.scm %}
-{% comment %} TODO: handle gitbox {% endcomment %}
+{%- if page.json.scmURL %}
     <tr>
-      <td>Source Code</td>
-      <td><a href="{{ page.json.scm }}">{{ page.json.scm }}</a></td>
+      <td>Source Code ({{ page.json.scmType }})</td>
+      <td><a href="{{ page.json.scmURL }}">{{ page.json.scmName }}</a></td>
     </tr>
 {%- endif %}
 {%- unless page.json.subproject %}

Modified: attic/site-jekyll/src/_plugins/generate_projects.rb
URL: 
http://svn.apache.org/viewvc/attic/site-jekyll/src/_plugins/generate_projects.rb?rev=1830041&r1=1830040&r2=1830041&view=diff
==============================================================================
--- attic/site-jekyll/src/_plugins/generate_projects.rb (original)
+++ attic/site-jekyll/src/_plugins/generate_projects.rb Wed Apr 25 01:17:23 2018
@@ -1,50 +1,89 @@
+# This script is called before the site is generated.
+# It processes the entries in _data/projects.json
+# and creates a page object for each using the template _layouts/project.html
+# These are added to the site.pages list which is then processed by Jekyll
+
 require 'json'
 
 module Jekyll
-  class CategoryPage < Page
-    def initialize(site, base, dir, p)
+  class ProjectPage < Page
+    def initialize(site, prj)
+
+      # fetch the html page name; 
+      # default to project name => lowercase and special chars => '-'
+      id = prj['id'] || (prj['name'].downcase.gsub(%r{[ /]},'-'))
+
       # These are needed by Jekyll
       @site = site
-      @dir = dir
-      id = p['id'] || (p['name'].downcase.gsub(%r{[ /]},'-'))
-      @page = "#{id}.html"
+      @dir = 'projects'
+      @page = "#{id}.html" # output file name
 
       self.process(@page)
-      self.read_yaml(File.join(base, '_layouts'), 'project.html')
-      p['id'] = id # in case we had to calculate it
+      self.read_yaml(File.join(site.source, '_layouts'), 'project.html')
+
+      # set up various data items used by the template
+
+      prj['id'] = id # in case we had to calculate it
       # Simplify template processing
-      p['dist'] = id.sub 'jakarta-','jakarta/'
+      prj['dist'] = id.sub 'jakarta-','jakarta/'
 
-      unless p['website'] # generate the website URL unless it is overridden
-        p['website'] = "http://#{p['project']}.apache.org/#{p['subproject']}"
+      unless prj['website'] # generate the website URL unless it is overridden
+        prj['website'] = 
"http://#{prj['project']}.apache.org/#{prj['subproject']}"
       end
-      if p['subproject']
-        p['full_slash'] = "#{p['project']}/#{p['subproject']}"
-        p['full_dash'] = "#{p['project']}-#{p['subproject']}"
+
+      if prj['subproject']
+        prj['full_slash'] = "#{prj['project']}/#{prj['subproject']}"
+        prj['full_dash'] = "#{prj['project']}-#{prj['subproject']}"
       else
-        p['full_slash'] = "#{p['project']}"
-        p['full_dash'] = "#{p['project']}"
+        prj['full_slash'] = "#{prj['project']}"
+        prj['full_dash'] = "#{prj['project']}"
       end
-      wiki=p['wiki']
+
+      wiki=prj['wiki']
       if wiki
-        p['wikiname'] = 
wiki.sub(%r{https?://},'').sub('/confluence/display/',': ')
+        prj['wikiname'] = 
wiki.sub(%r{https?://},'').sub('/confluence/display/',': ')
         if wiki.include? 'cwiki'
-          p['wikiname'].sub!(%r{/$},'')
+          prj['wikiname'].sub!(%r{/$},'')
         end
       end
-      self.data['json'] = p # pass the data to the page processor
+
+      if prj['bugzilla']
+        prj['issueURL'] = 
"https://bz.apache.org/bugzilla/buglist.cgi?product=#{prj['bugzilla']}"
+        prj['issueType'] = 'Bugzilla'
+      elsif prj['jira']
+        prj['issueURL'] = 
"https://issues.apache.org/jira/browse/#{prj['jira']}/"
+        prj['issueType'] = 'JIRA'
+      end
+
+      if prj['scm'] == 'svn'
+        prj['scmType'] = 'Subversion'
+        prj['scmName'] = 
"svn.apache.org/repos/asf/#{prj['project']}/#{prj['subproject']}"
+        prj['scmURL'] = 
"http://svn.apache.org/viewvc/#{prj['project']}/#{prj['subproject']}"
+      elsif prj['scm'] == 'git-wip'
+        prj['scmType'] = 'Git'
+        prj['scmName'] = 
"git-wip-us.apache.org/repos/asf?p=#{prj['project']}.git"
+        prj['scmURL'] = 
"https://git-wip-us.apache.org/repos/asf?p=#{prj['project']}.git"
+      elsif prj['scm']
+        prj['scmType'] = '?'
+        prj['scmName'] = prj['scm']
+        prj['scmURL'] = prj['scm']
+      end
+
+      # Create a new variable. This is used by the template to access the page 
data
+      # N.B. the variable name must agree with that used by the template
+      # Also it should not be one of the Jekyll page variable names.
+      self.data['json'] = prj # pass the massaged data from projects.json
     end
   end
 
-  class CategoryPageGenerator < Generator
+  class ProjectPageGenerator < Generator
     safe true
-
+    # entry point called by Jekyll
     def generate(site)
-      dir = 'projects'
-      base = site.source
-      site.data['projects'].each do |p|
-        # Create a new page
-        site.pages << CategoryPage.new(site, base, dir, p)
+      # iterate over the project objects in the _data/projects.json file
+      site.data['projects'].each do |prj|
+        # Create a new page object and add it to the list for Jekyll to 
generate
+        site.pages << ProjectPage.new(site, prj)
       end
     end
   end


Reply via email to