This is an automated email from the ASF dual-hosted git repository.

curcuru pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/whimsy.git


The following commit(s) were added to refs/heads/master by this push:
     new c368d9d  Common ui methods for site|pods.cgi
c368d9d is described below

commit c368d9d0f15c430c3c0e897cae118f9b2593830b
Author: Shane Curcuru <[email protected]>
AuthorDate: Wed May 9 20:12:02 2018 -0400

    Common ui methods for site|pods.cgi
---
 www/site.cgi => lib/whimsy/sitewebsite.rb | 100 +------
 www/site.cgi                              | 457 +++++++++++++++---------------
 2 files changed, 234 insertions(+), 323 deletions(-)

diff --git a/www/site.cgi b/lib/whimsy/sitewebsite.rb
old mode 100755
new mode 100644
similarity index 67%
copy from www/site.cgi
copy to lib/whimsy/sitewebsite.rb
index 6054c9d..46c3f6a
--- a/www/site.cgi
+++ b/lib/whimsy/sitewebsite.rb
@@ -1,94 +1,9 @@
 #!/usr/bin/env ruby
-PAGETITLE = "Apache Project Website Checks" # Wvisible:sites,brand
-
-# ensure that there is a path (even a slash will do) after the script name
-unless ENV['PATH_INFO'] and not ENV['PATH_INFO'].empty?
-  print "Status: 301 Moved Permanently\r\n"
-  print "Location: #{ENV['SCRIPT_URL']}/\r\n"
-  print "\r\n"
-  exit
-end
-
-$LOAD_PATH.unshift File.realpath(File.expand_path('../../lib', __FILE__))
-require 'json'
-require 'net/http'
-require 'time' # for httpdate
-require 'whimsy/sitestandards'
-
-# Gather and analyze scans for TLP websites
-cgi_for_tlps = true
-sites, crawl_time = SiteStandards.get_sites(cgi_for_tlps)
-checks_performed = SiteStandards.get_checks(cgi_for_tlps)
-analysis = SiteStandards.analyze(sites, checks_performed)
-
-# Allow CLI testing, e.g. "PATH_INFO=/ ruby www/site.cgi >test.json"
-# SCRIPT_NAME will always be set for a CGI invocation
-unless ENV['SCRIPT_NAME']
-  puts JSON.pretty_generate(analysis)
-  exit
-end
-
-# Only required for CGI use
-# if these are required earlier, the code creates an unnecessary 'assets' 
directory
-
-require 'whimsy/asf/themes'
+# Encapsulate (most) display of website checks between projects|podlings
 require 'wunderbar'
 require 'wunderbar/bootstrap'
-require 'wunderbar/jquery/stupidtable'
+require_relative '../whimsy/asf/themes'
 
-_html do
-  _head do
-    _style %{
-      .table td {font-size: smaller;}
-    }
-  end
-  _body? do
-    _whimsy_body(
-    title: PAGETITLE,
-    subtitle: "Checking #{cgi_for_tlps ? 'Project' : 'Podling'} Websites For 
required content",
-    related: {
-      "/committers/tools" => "Whimsy Tool Listing",
-      "https://www.apache.org/foundation/marks/pmcs#navigation"; => "Required 
PMC Links Policy",
-      "https://github.com/apache/whimsy/blob/master/www#{ENV['SCRIPT_NAME']}" 
=> "See This Source Code",
-      "mailto:[email protected]?subject=[SITE] Website Checker 
Question" => "Questions? Email Whimsy PMC"
-    },
-    helpblock: -> {
-      _p do
-        _ 'This script periodically crawls all Apache project and podling 
websites to check them for a few specific links or text blocks that all 
projects are expected to have.'
-        _ 'The checks include verifying that all '
-        _a 'required links', href: 
'https://www.apache.org/foundation/marks/pmcs#navigation'
-        _ ' appear on a project homepage, along with an "image" check if 
project logo files are in apache.org/img'
-      end
-      _p! do
-        _a 'View the crawler code', href: 
'https://github.com/apache/whimsy/blob/master/tools/site-scan.rb'
-        _ ', '
-        _a 'website display code', href: 
"https://github.com/apache/whimsy/blob/master/www#{ENV['SCRIPT_NAME']}"
-        _ ', and '
-        _a 'raw JSON data', href: 
"#{SiteStandards.get_url()}#{SiteStandards.get_filename(cgi_for_tlps)}"
-        _ '.'
-        _br
-        _ "Last crawl time: #{crawl_time} over #{sites.size} websites."
-      end
-    }
-    ) do
-      # Encapsulate data display (same for projects and podlings)
-      display_application(path_info, sites, analysis, checks_performed, 
cgi_for_tlps)
-    end
-    
-    _script %{
-      var table = $(".table").stupidtable();
-      table.on("aftertablesort", function (event, data) {
-        var th = $(this).find("th");
-        th.find(".arrow").remove();
-        var dir = $.fn.stupidtable.dir;
-        var arrow = data.direction === dir.ASC ? "&uarr;" : "&darr;";
-        th.eq(data.column).append('<span class="arrow">' + arrow +'</span>');
-        });
-    }
-  end
-end
-
-# Encapsulate (most) display of website checks between projects|podlings
 # Display data for a single project's checks
 # @param project id of project
 # @param links site data for that specific project
@@ -103,9 +18,9 @@ def display_project(project, links, analysis, checks, tlp = 
true)
         _span.glyphicon.glyphicon_home :aria_hidden
       end
       _span.glyphicon.glyphicon_menu_right
-      _ ' Results for project: '
+      _ "Results for #{tlp ? 'Project' : 'Podling'} "
       _a links['display_name'], href: links['uri']
-      _ ' Check Results column is the actual text found on the project 
homepage for this check (when applicable).'
+      _ ' Check Results column is the actual text found on the homepage for 
this check (when applicable).'
     }
   ) do
     _table.table.table_striped do
@@ -123,7 +38,6 @@ def display_project(project, links, analysis, checks, tlp = 
true)
             _td do
               _a col.capitalize, href: "../check/#{col}"
             end
-            
             if links[col] =~ /^https?:/
               _td class: cls do
                 _a links[col], href: links[col]
@@ -131,7 +45,6 @@ def display_project(project, links, analysis, checks, tlp = 
true)
             else
               _td links[col], class: cls
             end
-            
             _td do
               if cls != SiteStandards::SITE_PASS
                 if checks.keys.include? col
@@ -208,7 +121,6 @@ def display_check(col, sites, analysis, checks, tlp = true)
             _td do 
               _a links['display_name'], href: "../project/#{n}"
             end
-            
             if links[col] =~ /^https?:/
               _td class: SiteStandards.label(analysis, links, col, n) do
                 _a links[col], href: links[col]
@@ -257,13 +169,11 @@ def display_overview(sites, analysis, checks, tlp = true)
           end
         end
       end
-      
       sort_order = {
         SiteStandards::SITE_PASS => 1,
         SiteStandards::SITE_WARN => 2,
         SiteStandards::SITE_FAIL => 3
       }
-      
       _tbody do
         sites.each do |n, links|
           _tr do
@@ -297,7 +207,7 @@ def display_error(path)
   end
 end
 
-# Display our application's data - handles / and project|check/id paths
+# Display our application's data - handles / and project/id|check/id paths
 def display_application(path, sites, analysis, checks, tlp = true)
   if path =~ %r{/project/(.+)} # Display a single project
     if sites[$1]
diff --git a/www/site.cgi b/www/site.cgi
index 6054c9d..551e4f4 100755
--- a/www/site.cgi
+++ b/www/site.cgi
@@ -31,10 +31,11 @@ end
 # Only required for CGI use
 # if these are required earlier, the code creates an unnecessary 'assets' 
directory
 
-require 'whimsy/asf/themes'
 require 'wunderbar'
 require 'wunderbar/bootstrap'
 require 'wunderbar/jquery/stupidtable'
+require 'whimsy/asf/themes'
+require 'whimsy/sitewebsite'
 
 _html do
   _head do
@@ -88,231 +89,231 @@ _html do
   end
 end
 
-# Encapsulate (most) display of website checks between projects|podlings
-# Display data for a single project's checks
-# @param project id of project
-# @param links site data for that specific project
-# @param columns list of check types to report on
-# @param analysis complete scan data
-# @param tlp true if project (default); podling otherwise
-def display_project(project, links, analysis, checks, tlp = true)
-  _whimsy_panel_table(
-    title: "Site Check For #{tlp ? 'Project' : 'Podling'} - 
#{links['display_name']}",
-    helpblock: -> {
-      _a href: '../', aria_label: 'Home to site checker' do
-        _span.glyphicon.glyphicon_home :aria_hidden
-      end
-      _span.glyphicon.glyphicon_menu_right
-      _ ' Results for project: '
-      _a links['display_name'], href: links['uri']
-      _ ' Check Results column is the actual text found on the project 
homepage for this check (when applicable).'
-    }
-  ) do
-    _table.table.table_striped do
-      _tbody do
-        _thead do
-          _tr do
-            _th! 'Check Type'
-            _th! 'Check Results'
-            _th! 'Check Description'
-          end
-        end
-        checks.keys.each do |col|
-          cls = SiteStandards.label(analysis, links, col, project)
-          _tr do
-            _td do
-              _a col.capitalize, href: "../check/#{col}"
-            end
-            
-            if links[col] =~ /^https?:/
-              _td class: cls do
-                _a links[col], href: links[col]
-              end
-            else
-              _td links[col], class: cls
-            end
-            
-            _td do
-              if cls != SiteStandards::SITE_PASS
-                if checks.keys.include? col
-                  if checks[col][SiteStandards::CHECK_TYPE]
-                    _ 'URL expected to match regular expression: '
-                    _code checks[col][SiteStandards::CHECK_VALIDATE].source
-                  else
-                    _ 'Text of a link expected to match regular expression: '
-                    _code checks[col][SiteStandards::CHECK_TEXT].source
-                  end
-                    _br
-                    _a checks[col][SiteStandards::CHECK_DOC], href: 
checks[col][SiteStandards::CHECK_POLICY]
-                else
-                  _ ''
-                end
-              end
-            end
-          end
-        end
-      end
-    end
-  end
-end
-
-# Display data for a single check across all projects/podlings
-# @param col id of check to display
-# @param sites site data for all projects
-# @param analysis complete scan data
-# @param checks complete set of checks performed
-# @param tlp true if project (default); podling otherwise
-def display_check(col, sites, analysis, checks, tlp = true)
-  _whimsy_panel_table(
-    title: "Site Check Of Type - #{col.capitalize}",
-    helpblock: -> {
-      _a href: '../', aria_label: 'Home to site checker' do
-        _span.glyphicon.glyphicon_home :aria_hidden
-      end
-      _span.glyphicon.glyphicon_menu_right
-      if checks.keys.include? col
-        if checks[col][SiteStandards::CHECK_TYPE]
-          _ 'Check Results URL expected to match regular expression: '
-          _code checks[col][SiteStandards::CHECK_VALIDATE].source
-        else
-          _ 'Check Results Text of a link expected to match regular 
expression: '
-          _code checks[col][SiteStandards::CHECK_TEXT].source
-        end
-        if checks.include? col
-          _br
-          _a checks[col][SiteStandards::CHECK_DOC], href: 
checks[col][SiteStandards::CHECK_POLICY]
-        end
-        _li.small " Click column badges to sort"
-      else
-        _span.text_danger "WARNING: the site checker may not understand type: 
#{col}, results may not be complete/available."
-      end
-    }
-  ) do
-    _table.table.table_condensed.table_striped do
-      _thead do
-        _tr do
-          _th! "#{tlp ? 'Project' : 'Podling'}", data_sort: 'string-ins'
-          _th! data_sort: 'string' do 
-            _ 'Check Results'
-            _br
-            analysis[0][col].each do |cls, val|
-              _ ' '
-              _span.label val, class: cls
-            end
-          end
-        end
-      end
-      _tbody do
-        sites.each do |n, links|
-          _tr do
-            _td do 
-              _a links['display_name'], href: "../project/#{n}"
-            end
-            
-            if links[col] =~ /^https?:/
-              _td class: SiteStandards.label(analysis, links, col, n) do
-                _a links[col], href: links[col]
-              end
-            else
-              _td links[col], class: SiteStandards.label(analysis, links, col, 
n) 
-            end
-          end
-        end
-      end
-    end
-  end
-end
-
-# Display an overview of all checks/sites
-# @param sites site data for all projects
-# @param analysis complete scan data
-# @param checks complete set of checks performed
-# @param tlp true if project (default); podling otherwise
-def display_overview(sites, analysis, checks, tlp = true)
-  _whimsy_panel_table(
-    title: "Site Check - All #{tlp ? 'Project' : 'Podling'} Results",
-    helpblock: -> {
-      _ul.list_inline do
-        _li.small "Data key: "
-        analysis[1].each do |cls, desc|
-          _li.label desc, class: cls
-        end
-        _li.small " Click column badges to sort"
-      end
-    }
-  ) do
-    _table.table.table_condensed.table_striped do
-      _thead do  
-        _tr do
-          _th! "#{tlp ? 'Project' : 'Podling'}", data_sort: 'string-ins'
-          checks.keys.each do |col|
-            _th! data_sort: 'string' do 
-              _a col.capitalize, href: "check/#{col}"
-              _br
-              analysis[0][col].each do |cls, val|
-                _ ' '
-                _span.label val, class: cls
-              end
-            end
-          end
-        end
-      end
-      
-      sort_order = {
-        SiteStandards::SITE_PASS => 1,
-        SiteStandards::SITE_WARN => 2,
-        SiteStandards::SITE_FAIL => 3
-      }
-      
-      _tbody do
-        sites.each do |n, links|
-          _tr do
-            _td do 
-              _a "#{links['display_name']}", href: "project/#{n}"
-            end
-            checks.keys.each do |c|
-              cls = SiteStandards.label(analysis, links, c, n)
-              _td '', class: cls, data_sort_value: sort_order[cls]
-            end
-          end
-        end
-      end
-    end
-  end
-end
-
-# Display an error page if a suburl we're given isn't supported
-def display_error(path)
-  _whimsy_panel_table(
-    title: "ERROR - bad url provided",
-    helpblock: -> {
-      _a href: '../', aria_label: 'Home to site checker' do
-        _span.glyphicon.glyphicon_home :aria_hidden
-      end
-      _span.glyphicon.glyphicon_menu_right
-      _span.text_danger "ERROR: The path #{path} is not a recognized command 
for this tool, sorry! "
-    }
-  ) do
-    _a.bold 'ERROR - please try again.', href: '../'
-  end
-end
-
-# Display our application's data - handles / and project|check/id paths
-def display_application(path, sites, analysis, checks, tlp = true)
-  if path =~ %r{/project/(.+)} # Display a single project
-    if sites[$1]
-      display_project($1, sites[$1], analysis, checks, tlp)
-    else
-      display_error(path)
-    end
-  elsif path =~ %r{/check/(.+)} # Display a single check
-    if checks[$1]
-      display_check($1, sites, analysis, checks, tlp)
-    else
-      display_error(path)
-    end
-  else
-    display_overview(sites, analysis, checks, tlp)
-  end
-end
+# # Encapsulate (most) display of website checks between projects|podlings
+# # Display data for a single project's checks
+# # @param project id of project
+# # @param links site data for that specific project
+# # @param columns list of check types to report on
+# # @param analysis complete scan data
+# # @param tlp true if project (default); podling otherwise
+# def display_project(project, links, analysis, checks, tlp = true)
+#   _whimsy_panel_table(
+#     title: "Site Check For #{tlp ? 'Project' : 'Podling'} - 
#{links['display_name']}",
+#     helpblock: -> {
+#       _a href: '../', aria_label: 'Home to site checker' do
+#         _span.glyphicon.glyphicon_home :aria_hidden
+#       end
+#       _span.glyphicon.glyphicon_menu_right
+#       _ ' Results for project: '
+#       _a links['display_name'], href: links['uri']
+#       _ ' Check Results column is the actual text found on the project 
homepage for this check (when applicable).'
+#     }
+#   ) do
+#     _table.table.table_striped do
+#       _tbody do
+#         _thead do
+#           _tr do
+#             _th! 'Check Type'
+#             _th! 'Check Results'
+#             _th! 'Check Description'
+#           end
+#         end
+#         checks.keys.each do |col|
+#           cls = SiteStandards.label(analysis, links, col, project)
+#           _tr do
+#             _td do
+#               _a col.capitalize, href: "../check/#{col}"
+#             end
+# 
+#             if links[col] =~ /^https?:/
+#               _td class: cls do
+#                 _a links[col], href: links[col]
+#               end
+#             else
+#               _td links[col], class: cls
+#             end
+# 
+#             _td do
+#               if cls != SiteStandards::SITE_PASS
+#                 if checks.keys.include? col
+#                   if checks[col][SiteStandards::CHECK_TYPE]
+#                     _ 'URL expected to match regular expression: '
+#                     _code checks[col][SiteStandards::CHECK_VALIDATE].source
+#                   else
+#                     _ 'Text of a link expected to match regular expression: '
+#                     _code checks[col][SiteStandards::CHECK_TEXT].source
+#                   end
+#                     _br
+#                     _a checks[col][SiteStandards::CHECK_DOC], href: 
checks[col][SiteStandards::CHECK_POLICY]
+#                 else
+#                   _ ''
+#                 end
+#               end
+#             end
+#           end
+#         end
+#       end
+#     end
+#   end
+# end
+# 
+# # Display data for a single check across all projects/podlings
+# # @param col id of check to display
+# # @param sites site data for all projects
+# # @param analysis complete scan data
+# # @param checks complete set of checks performed
+# # @param tlp true if project (default); podling otherwise
+# def display_check(col, sites, analysis, checks, tlp = true)
+#   _whimsy_panel_table(
+#     title: "Site Check Of Type - #{col.capitalize}",
+#     helpblock: -> {
+#       _a href: '../', aria_label: 'Home to site checker' do
+#         _span.glyphicon.glyphicon_home :aria_hidden
+#       end
+#       _span.glyphicon.glyphicon_menu_right
+#       if checks.keys.include? col
+#         if checks[col][SiteStandards::CHECK_TYPE]
+#           _ 'Check Results URL expected to match regular expression: '
+#           _code checks[col][SiteStandards::CHECK_VALIDATE].source
+#         else
+#           _ 'Check Results Text of a link expected to match regular 
expression: '
+#           _code checks[col][SiteStandards::CHECK_TEXT].source
+#         end
+#         if checks.include? col
+#           _br
+#           _a checks[col][SiteStandards::CHECK_DOC], href: 
checks[col][SiteStandards::CHECK_POLICY]
+#         end
+#         _li.small " Click column badges to sort"
+#       else
+#         _span.text_danger "WARNING: the site checker may not understand 
type: #{col}, results may not be complete/available."
+#       end
+#     }
+#   ) do
+#     _table.table.table_condensed.table_striped do
+#       _thead do
+#         _tr do
+#           _th! "#{tlp ? 'Project' : 'Podling'}", data_sort: 'string-ins'
+#           _th! data_sort: 'string' do 
+#             _ 'Check Results'
+#             _br
+#             analysis[0][col].each do |cls, val|
+#               _ ' '
+#               _span.label val, class: cls
+#             end
+#           end
+#         end
+#       end
+#       _tbody do
+#         sites.each do |n, links|
+#           _tr do
+#             _td do 
+#               _a links['display_name'], href: "../project/#{n}"
+#             end
+# 
+#             if links[col] =~ /^https?:/
+#               _td class: SiteStandards.label(analysis, links, col, n) do
+#                 _a links[col], href: links[col]
+#               end
+#             else
+#               _td links[col], class: SiteStandards.label(analysis, links, 
col, n) 
+#             end
+#           end
+#         end
+#       end
+#     end
+#   end
+# end
+# 
+# # Display an overview of all checks/sites
+# # @param sites site data for all projects
+# # @param analysis complete scan data
+# # @param checks complete set of checks performed
+# # @param tlp true if project (default); podling otherwise
+# def display_overview(sites, analysis, checks, tlp = true)
+#   _whimsy_panel_table(
+#     title: "Site Check - All #{tlp ? 'Project' : 'Podling'} Results",
+#     helpblock: -> {
+#       _ul.list_inline do
+#         _li.small "Data key: "
+#         analysis[1].each do |cls, desc|
+#           _li.label desc, class: cls
+#         end
+#         _li.small " Click column badges to sort"
+#       end
+#     }
+#   ) do
+#     _table.table.table_condensed.table_striped do
+#       _thead do  
+#         _tr do
+#           _th! "#{tlp ? 'Project' : 'Podling'}", data_sort: 'string-ins'
+#           checks.keys.each do |col|
+#             _th! data_sort: 'string' do 
+#               _a col.capitalize, href: "check/#{col}"
+#               _br
+#               analysis[0][col].each do |cls, val|
+#                 _ ' '
+#                 _span.label val, class: cls
+#               end
+#             end
+#           end
+#         end
+#       end
+# 
+#       sort_order = {
+#         SiteStandards::SITE_PASS => 1,
+#         SiteStandards::SITE_WARN => 2,
+#         SiteStandards::SITE_FAIL => 3
+#       }
+# 
+#       _tbody do
+#         sites.each do |n, links|
+#           _tr do
+#             _td do 
+#               _a "#{links['display_name']}", href: "project/#{n}"
+#             end
+#             checks.keys.each do |c|
+#               cls = SiteStandards.label(analysis, links, c, n)
+#               _td '', class: cls, data_sort_value: sort_order[cls]
+#             end
+#           end
+#         end
+#       end
+#     end
+#   end
+# end
+# 
+# # Display an error page if a suburl we're given isn't supported
+# def display_error(path)
+#   _whimsy_panel_table(
+#     title: "ERROR - bad url provided",
+#     helpblock: -> {
+#       _a href: '../', aria_label: 'Home to site checker' do
+#         _span.glyphicon.glyphicon_home :aria_hidden
+#       end
+#       _span.glyphicon.glyphicon_menu_right
+#       _span.text_danger "ERROR: The path #{path} is not a recognized command 
for this tool, sorry! "
+#     }
+#   ) do
+#     _a.bold 'ERROR - please try again.', href: '../'
+#   end
+# end
+# 
+# # Display our application's data - handles / and project|check/id paths
+# def display_application(path, sites, analysis, checks, tlp = true)
+#   if path =~ %r{/project/(.+)} # Display a single project
+#     if sites[$1]
+#       display_project($1, sites[$1], analysis, checks, tlp)
+#     else
+#       display_error(path)
+#     end
+#   elsif path =~ %r{/check/(.+)} # Display a single check
+#     if checks[$1]
+#       display_check($1, sites, analysis, checks, tlp)
+#     else
+#       display_error(path)
+#     end
+#   else
+#     display_overview(sites, analysis, checks, tlp)
+#   end
+# end
 

-- 
To stop receiving notification emails like this one, please contact
[email protected].

Reply via email to