--- /dev/null
+require 'rexml/document'
+UCS = /^[0-9a-fA-F]+$/
+CODEPOINT = /^U\+[0-9a-fA-F]+$/
+
+class ApplicationController < ActionController::Base
+ helper :all # include all helpers, all the time
+ protect_from_forgery # See ActionController::RequestForgeryProtection for details
+
+ # Scrub sensitive parameters from your log
+ # filter_parameter_logging :password
+
+ def ucs2char(ucs)
+ return nil unless ucs =~ CODEPOINT
+ code = ucs.slice(2, ucs.size)
+ return code2char(code)
+ end
+ def code2char(code)
+ return [code.hex].pack("U*")
+ end
+ def char2ucs(char)
+ # TODO: Check char in codespace
+ # Unicode codespace is a range of integers
+ # from 0 to 10FFFF_hex
+ return format("U+%04X", char.unpack("U")[0])
+ end
+ def codepoint2ucs(codepoint)
+ return format("U+%04X", codepoint)
+ end
+ def ucs2codepoint(ucs)
+ return nil unless ucs =~ CODEPOINT
+ code = ucs.slice(2, ucs.size)
+ return code.hex
+ end
+ def process_char(c)
+ if c =~ UCS then
+ ucs = "U+" + c
+ char = ucs2char(ucs)
+ else
+ char = c
+ end
+ return [char2ucs(char), char]
+ end
+
+ def print_note(note)
+ doc = REXML::Document.new note
+ doc.elements.each("//original_text") do |original|
+ original.elements.each("//rewrite_text") do |rewrite|
+ if rewrite then
+ rtext = rewrite.text
+ relem = REXML::Element.new("span")
+ relem.add_attribute("style", "font_color:red")
+ relem.add_text(rtext)
+ original.parent.insert_after(original, relem)
+ end
+ end
+ otext = original.text
+ replace = REXML::Element.new("del")
+ replace.add_text(otext)
+ original.parent.replace_child(original, replace)
+ end
+ return doc.to_s
+ end
+end
--- /dev/null
+class DaxuController < ApplicationController
+ layout "main"
+
+ def index
+ vols = DxVolume.find(:all)
+ @vols = Array.new
+ vols.each do |vol|
+ radicals = DxRadical.find(:all, :conditions =>
+ ["volume_id = ?", vol.id])
+ @vols.push([vol, radicals])
+ end
+ end
+ def radical
+ radical_id = params[:id]
+ @radical = DxRadical.find(:first, :conditions => ["id = ?", radical_id])
+ @volume = DxVolume.find(:first, :conditions => ["id = ?", @radical.volume_id])
+ @wordheads = DxWordhead.find(:all, :conditions => ["radical_id = ?", radical_id])
+
+ # TODO: sw -> char of sw
+ @words = Array.new
+ @wordheads.each do |word|
+ sw = ucs2char("U+" + word.sw)
+ @words.push([word, sw])
+ end
+ end
+ def word
+ c = params[:char]
+ return nil unless c
+ (@ucs, @char) = process_char(c)
+
+ @dx_words = Array.new
+ wordheads = DxWordhead.find(:all, :conditions => ["name = ?", @char])
+ wordheads.each do |word|
+ wordid = word.wordid
+ rad = DxRadical.find(:first, :conditions => ["id = ?", word.radical_id])
+ vol = DxVolume.find(:first, :conditions => ["id = ?", rad.volume_id])
+
+ # TODO: sw -> char of sw
+ sw = ucs2char("U+" + word.sw)
+ @dx_words.push([vol, rad, word, sw])
+ end
+ end
+end
--- /dev/null
+# Methods added to this helper will be available to all templates in the application.
+module ApplicationHelper
+end
--- /dev/null
+module DaxuHelper
+end
--- /dev/null
+class DxRadical < ActiveRecord::Base
+ belongs_to :volume
+end
--- /dev/null
+class DxVolume < ActiveRecord::Base
+end
--- /dev/null
+class DxWordhead < ActiveRecord::Base
+ belongs_to :radical
+end
--- /dev/null
+<ul>
+<% @vols.each do |volinfo|%>
+ <% (vol, radicals) = volinfo %>
+ <li>
+ <%= vol.title %>
+ <% radicals.each do |rad| %>
+ <%= link_to(rad.name, :controller => "daxu",
+ :action => "radical", :id => rad.id) %>
+ <% end %>
+ </li>
+<% end %>
+</ul>
--- /dev/null
+<%= link_to("大徐", :controller => "daxu", :action => "index") %>
+<br />
+
+<p>
+<%= @volume.title %> <%= @radical.name %>部<br />
+<% @words.each do |word|%>
+ <% (wordhead, sw) = word %>
+ <span class="s"><%= sw %></span>
+ <%= link_to(wordhead.name, :controller => "daxu",
+ :action => "word", :char => wordhead.name) %>
+<% end %>
+</p>
--- /dev/null
+<%= link_to("大徐", :controller => "daxu", :action => "index") %>
+
+<% form_tag(:controller => "daxu", :action => "word", :method => "get") do %>
+ <%= label_tag(:char, "Search for:") %>
+ <%= text_field_tag(:char, "", :size => "5") %>
+ <%= submit_tag("Search") %>
+<% end %>
+
+<% if @char then %>
+ <span style="font-size: 150%"><%= @char %>
+ ... Han Morphismデータの埋込</span><br /><hr />
+ <h3>説文解字(大徐本)</h3>
+ <% @dx_words.each do |wordinfo|%>
+ <% (vol, rad, word, sw) = wordinfo %>
+ <%= vol.title %>
+ <%= link_to(rad.name + "部", :controller => "daxu",
+ :action => "radical", :id => rad.id) %>
+ <br />
+ <div>
+ <span class="s"><%= sw %></span>(<%= word.name %>)
+ <span style="font-size: 140%"><%= word.exp %></span>
+ [<%= word.fanqie %> <%= word.pinyin %>]
+ </div>
+ <% end %>
+<% end %>
--- /dev/null
+<html>
+<head>
+ <title>Han Morphism</title>
+ <META http-equiv="Content-Type" content="text/html; charset=utf8">
+ <%= stylesheet_link_tag("sw") %>
+</head>
+<body>
+<h2>汉态射
+ <span style="font-size:60%"><%= yield :head %></span>
+ <span style="font-size:90%;font-style:italic">Han Morphism System</span>
+ <span style="font-size:60%">Ver.0.3.0</span>
+</h2>
+<%= yield %>
+</body>
--- /dev/null
+ActionController::Routing::Routes.draw do |map|
+ # The priority is based upon order of creation: first created -> highest priority.
+
+ # Sample of regular route:
+ # map.connect 'products/:id', :controller => 'catalog', :action => 'view'
+ # Keep in mind you can assign values other than :controller and :action
+
+ # Sample of named route:
+ # map.purchase 'products/:id/purchase', :controller => 'catalog', :action => 'purchase'
+ # This route can be invoked with purchase_url(:id => product.id)
+
+ # Sample resource route (maps HTTP verbs to controller actions automatically):
+ # map.resources :products
+
+ # Sample resource route with options:
+ # map.resources :products, :member => { :short => :get, :toggle => :post }, :collection => { :sold => :get }
+
+ # Sample resource route with sub-resources:
+ # map.resources :products, :has_many => [ :comments, :sales ], :has_one => :seller
+
+ # Sample resource route with more complex sub-resources
+ # map.resources :products do |products|
+ # products.resources :comments
+ # products.resources :sales, :collection => { :recent => :get }
+ # end
+
+ # Sample resource route within a namespace:
+ # map.namespace :admin do |admin|
+ # # Directs /admin/products/* to Admin::ProductsController (app/controllers/admin/products_controller.rb)
+ # admin.resources :products
+ # end
+
+ # You can have the root of your site routed with map.root -- just remember to delete public/index.html.
+ # map.root :controller => "welcome"
+ map.root :controller => "daxu"
+
+ # See how all your routes lay out with "rake routes"
+
+ # Install the default routes as the lowest priority.
+ # Note: These default routes make all actions in every controller accessible via GET requests. You should
+ # consider removing or commenting them out if you're using named routes and resources.
+ map.connect ':controller/:action/:id'
+ map.connect ':controller/:action/:id.:format'
+end
--- /dev/null
+# This file is auto-generated from the current state of the database. Instead of editing this file,
+# please use the migrations feature of Active Record to incrementally modify your database, and
+# then regenerate this schema definition.
+#
+# Note that this schema.rb definition is the authoritative source for your database schema. If you need
+# to create the application database on another system, you should be using db:schema:load, not running
+# all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations
+# you'll amass, the slower it'll run and the greater likelihood for issues).
+#
+# It's strongly recommended to check this file into your version control system.
+
+ActiveRecord::Schema.define(:version => 20110911083104) do
+
+ create_table "dx_radicals", :force => true do |t|
+ t.string "name"
+ t.string "num"
+ t.integer "volume_id"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+ create_table "dx_volumes", :force => true do |t|
+ t.string "title"
+ t.string "num"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+ create_table "dx_wordheads", :force => true do |t|
+ t.string "name"
+ t.string "wordid"
+ t.string "sw"
+ t.string "pinyin"
+ t.string "fanqie"
+ t.text "exp"
+ t.integer "radical_id"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
+end
--- /dev/null
+@font-face {
+ font-family: "SW";
+ src: url('http://www.wenzi.cn/shuzi/shuowen/download/SW.ttf') format("truetype");
+ /* src: url('./SW.ttf') format("truetype"); */
+}
+
+.s { font-family: SW, 'MS 明朝', serif; font-size: 300%; }
+
+
+/* SBGY */
+.original { text-decoration: line-through; }
+.rewrite { background-color: plum; }
+.added { background-color: plum; }
+
+/* Shuowen */
+.explanation { font-size: 150%; }
+.duan_note { }
\ No newline at end of file