OSDN Git Service

Initial commit
authorVMplanet Virtual Machines <vmplanet@kubuntu-vm.(none)>
Sun, 11 Sep 2011 14:37:31 +0000 (23:37 +0900)
committerVMplanet Virtual Machines <vmplanet@kubuntu-vm.(none)>
Sun, 11 Sep 2011 14:37:31 +0000 (23:37 +0900)
14 files changed:
daxu/app/controllers/application_controller.rb [new file with mode: 0644]
daxu/app/controllers/daxu_controller.rb [new file with mode: 0644]
daxu/app/helpers/application_helper.rb [new file with mode: 0644]
daxu/app/helpers/daxu_helper.rb [new file with mode: 0644]
daxu/app/models/dx_radical.rb [new file with mode: 0644]
daxu/app/models/dx_volume.rb [new file with mode: 0644]
daxu/app/models/dx_wordhead.rb [new file with mode: 0644]
daxu/app/views/daxu/index.html.erb [new file with mode: 0644]
daxu/app/views/daxu/radical.html.erb [new file with mode: 0644]
daxu/app/views/daxu/word.html.erb [new file with mode: 0644]
daxu/app/views/layouts/main.html.erb [new file with mode: 0644]
daxu/config/routes.rb [new file with mode: 0644]
daxu/db/schema.rb [new file with mode: 0644]
daxu/public/stylesheets/sw.css [new file with mode: 0644]

diff --git a/daxu/app/controllers/application_controller.rb b/daxu/app/controllers/application_controller.rb
new file mode 100644 (file)
index 0000000..85a7f2e
--- /dev/null
@@ -0,0 +1,63 @@
+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
diff --git a/daxu/app/controllers/daxu_controller.rb b/daxu/app/controllers/daxu_controller.rb
new file mode 100644 (file)
index 0000000..a5bfb12
--- /dev/null
@@ -0,0 +1,43 @@
+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
diff --git a/daxu/app/helpers/application_helper.rb b/daxu/app/helpers/application_helper.rb
new file mode 100644 (file)
index 0000000..22a7940
--- /dev/null
@@ -0,0 +1,3 @@
+# Methods added to this helper will be available to all templates in the application.
+module ApplicationHelper
+end
diff --git a/daxu/app/helpers/daxu_helper.rb b/daxu/app/helpers/daxu_helper.rb
new file mode 100644 (file)
index 0000000..b9de0e4
--- /dev/null
@@ -0,0 +1,2 @@
+module DaxuHelper
+end
diff --git a/daxu/app/models/dx_radical.rb b/daxu/app/models/dx_radical.rb
new file mode 100644 (file)
index 0000000..63cb508
--- /dev/null
@@ -0,0 +1,3 @@
+class DxRadical < ActiveRecord::Base
+  belongs_to :volume
+end
diff --git a/daxu/app/models/dx_volume.rb b/daxu/app/models/dx_volume.rb
new file mode 100644 (file)
index 0000000..cf69bea
--- /dev/null
@@ -0,0 +1,2 @@
+class DxVolume < ActiveRecord::Base
+end
diff --git a/daxu/app/models/dx_wordhead.rb b/daxu/app/models/dx_wordhead.rb
new file mode 100644 (file)
index 0000000..c6e1dcc
--- /dev/null
@@ -0,0 +1,3 @@
+class DxWordhead < ActiveRecord::Base
+  belongs_to :radical
+end
diff --git a/daxu/app/views/daxu/index.html.erb b/daxu/app/views/daxu/index.html.erb
new file mode 100644 (file)
index 0000000..2d83ea2
--- /dev/null
@@ -0,0 +1,12 @@
+<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>
diff --git a/daxu/app/views/daxu/radical.html.erb b/daxu/app/views/daxu/radical.html.erb
new file mode 100644 (file)
index 0000000..3fcbc6d
--- /dev/null
@@ -0,0 +1,12 @@
+<%= 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>
diff --git a/daxu/app/views/daxu/word.html.erb b/daxu/app/views/daxu/word.html.erb
new file mode 100644 (file)
index 0000000..ba73266
--- /dev/null
@@ -0,0 +1,25 @@
+<%= 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 %>
diff --git a/daxu/app/views/layouts/main.html.erb b/daxu/app/views/layouts/main.html.erb
new file mode 100644 (file)
index 0000000..a1ad677
--- /dev/null
@@ -0,0 +1,14 @@
+<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>
diff --git a/daxu/config/routes.rb b/daxu/config/routes.rb
new file mode 100644 (file)
index 0000000..44ce8f2
--- /dev/null
@@ -0,0 +1,44 @@
+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
diff --git a/daxu/db/schema.rb b/daxu/db/schema.rb
new file mode 100644 (file)
index 0000000..96b025f
--- /dev/null
@@ -0,0 +1,41 @@
+# 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
diff --git a/daxu/public/stylesheets/sw.css b/daxu/public/stylesheets/sw.css
new file mode 100644 (file)
index 0000000..e7649be
--- /dev/null
@@ -0,0 +1,17 @@
+@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