[ruby-oci8-commit] [291] web/hiki_src: Add customization as follows to hiki 0.8.7.

nobody at rubyforge.org nobody at rubyforge.org
Fri Oct 17 08:00:48 EDT 2008


Revision: 291
Author:   kubo
Date:     2008-10-17 08:00:47 -0400 (Fri, 17 Oct 2008)

Log Message:
-----------
Add customization as follows to hiki 0.8.7.

1. It makes links for static pages when it is accessed by wget.

2. If a heading title looks like a function call, it add an
   anchor by the function name.

   e.g.
     !! logoff()  -->   <h2><a name="logoff">logoff()</a><h2>

3. If a wiki link has '#', it assumes the the left side is a
   wiki name and the right side is an anchor.

   e.g.
     [[OCI8#logoff]] -->  <a href="api_OCI8.html#logoff">OCI8#logoff</a>

Modified Paths:
--------------
    web/hiki_src/misc/plugin/google-sitemaps.rb
    web/hiki_src/style/default/html_formatter.rb

Added Paths:
-----------
    web/hiki_src/plugin/99ruby-oci8.rb

Modified: web/hiki_src/misc/plugin/google-sitemaps.rb
===================================================================
--- web/hiki_src/misc/plugin/google-sitemaps.rb	2008-10-16 13:59:41 UTC (rev 290)
+++ web/hiki_src/misc/plugin/google-sitemaps.rb	2008-10-17 12:00:47 UTC (rev 291)
@@ -7,15 +7,21 @@
   sitemaps = %Q!<?xml version="1.0" encoding="UTF-8"?>\n!
   sitemaps << %Q!<urlset xmlns="http://www.google.com/schemas/sitemap/0.84">\n!
   site_last_modified = nil
+  is_wget = /wget/i =~ ENV['HTTP_USER_AGENT']
   @db.page_info.each do |page|
     name = page.keys[0]
     lastmod = page.values[0][:last_modified]
     if site_last_modified.nil? or site_last_modified < lastmod
       site_last_modified = lastmod
     end
+    if is_wget
+      link = "#{@conf.base_url}#{name.escape}.html"
+    else
+      link = "#{@conf.index_url}?#{name.escape}"
+    end
     sitemaps << <<_E
   <url>
-    <loc>#{@conf.index_url}?#{name.escape}</loc>
+    <loc>#{link}</loc>
     <lastmod>#{lastmod.utc.strftime('%Y-%m-%dT%H:%M:%S+00:00')}</lastmod>
   </url>
 _E

Added: web/hiki_src/plugin/99ruby-oci8.rb
===================================================================
--- web/hiki_src/plugin/99ruby-oci8.rb	                        (rev 0)
+++ web/hiki_src/plugin/99ruby-oci8.rb	2008-10-17 12:00:47 UTC (rev 291)
@@ -0,0 +1,71 @@
+
+def wget?
+  /wget/i =~ ENV['HTTP_USER_AGENT']
+end
+
+alias :orig_hiki_url :hiki_url
+
+def hiki_url(page)
+  if wget?
+    "#{page.escape}.html"
+  else
+    orig_hiki_url(page)
+  end
+end
+
+alias :orig_hiki_anchor :hiki_anchor
+
+def hiki_anchor( page, display_text )
+  if /^(\w+)\(.*\)$/ =~ display_text
+    display_text = %Q!<a name="#{$1}">#{display_text}</a>!
+  end
+  if wget?
+    if /(\w+)(#\w+)/ =~ page
+      page = $1
+      anchor = $2
+    else
+      anchor = ''
+    end
+    if page == 'FrontPage' then
+      make_anchor("index.html#{anchor}", display_text)
+    else
+      make_anchor("#{page.escape}.html#{anchor}", display_text)
+    end
+  else
+    orig_hiki_anchor(page, display_text)
+  end
+end
+
+alias :orig_create_menu :create_menu
+
+def create_menu(data, command)
+  if wget?
+    []
+  else
+    orig_create_menu(data, command)
+  end
+end
+
+alias :orig_editable? :editable?
+
+def editable?( page = @page )
+  if wget?
+    false
+  else
+    orig_editable?(page)
+  end
+end
+
+def logo
+  '<a href="index.html" class="logo">ruby-oci8</a>'
+end
+
+def link_to_japanese
+  '<a href="../ja/index.html">Japanese</a>'
+end
+
+def link_to_english
+  '<a href="../en/index.html">English</a>'
+end
+
+export_plugin_methods(:logo, :link_to_japanese, :link_to_english)

Modified: web/hiki_src/style/default/html_formatter.rb
===================================================================
--- web/hiki_src/style/default/html_formatter.rb	2008-10-16 13:59:41 UTC (rev 290)
+++ web/hiki_src/style/default/html_formatter.rb	2008-10-17 12:00:47 UTC (rev 291)
@@ -28,6 +28,20 @@
       s = replace_wikiname( s ) if @conf.use_wikiname
       s = replace_link( s )
       s = replace_auto_link( s ) if @conf.auto_link
+      s = s.gsub(%r!<h(\d)>(.*?)</h\1>!) do |m|
+        level = $1
+        title = $2
+        case title
+        when /^(?:[A-Z][\w:]+\.)?([a-z0-9_]+)\(.*?\)$/
+          %Q!<h#{level}><a name="#{$1}">#{title}</a></h#{level}>!
+        when /^([a-z_]+)\s*=.*$/
+          %Q!<h#{level}><a name="#{$1}=">#{title}</a></h#{level}>!
+        when /^[a-z_]+$/
+          %Q!<h#{level}><a name="#{title}">#{title}</a></h#{level}>!
+        else
+          m
+        end
+      end
       s = replace_heading( s )
       s = replace_plugin( s ) if @conf.use_plugin
       @html_converted = s
@@ -132,11 +146,12 @@
           @plugin.make_anchor(u, k, 'external')
         else
           u = u.unescapeHTML
+          u, anchor = $1, $2 if /([\w:]+)(#\w+)/ =~ u
           u = @aliaswiki.aliaswiki_names.key( u ) || u # alias wiki
           if /(.*)(#l\d+)\z/ =~ u
             u, anchor = $1, $2
           else
-            anchor = ''
+            anchor ||= ''
           end
           if @db.exist?( u ) # page name
             k = @plugin.page_name( k ) if k == u




More information about the ruby-oci8-commit mailing list