Permalink
Browse files

new file

  • Loading branch information...
1 parent 75cdb8e commit 4f88b5e0c0169108006ac81813ef2d1832147553 @biti biti committed Apr 9, 2011
Showing with 63 additions and 0 deletions.
  1. +50 −0 lib/note.rb
  2. +13 −0 setting.rb
View
@@ -0,0 +1,50 @@
+require File.dirname(__FILE__) + '/../vendor/maruku/maruku'
+
+$LOAD_PATH.unshift File.dirname(__FILE__) + '/../vendor/syntax'
+require 'syntax/convertors/html'
+
+class Note < Sequel::Model
+ unless table_exists?
+ set_schema do
+ primary_key :id
+ text :body
+ timestamp :created_at
+ end
+ create_table
+ end
+
+ def body_html
+ to_html(body)
+ end
+
+ def more?
+ @more ||= body.match(/.{20}.*?\n(.*)/m)
+ end
+
+ ########
+
+ def to_html(markdown)
+ out = []
+ noncode = []
+ code_block = nil
+ markdown.split("\n").each do |line|
+ if !code_block and line.strip.downcase == '<code>'
+ out << Maruku.new(noncode.join("\n")).to_html
+ noncode = []
+ code_block = []
+ elsif code_block and line.strip.downcase == '</code>'
+ convertor = Syntax::Convertors::HTML.for_syntax "ruby"
+ highlighted = convertor.convert(code_block.join("\n"))
+ out << "<code>#{highlighted}</code>"
+ code_block = nil
+ elsif code_block
+ code_block << line
+ else
+ noncode << line
+ end
+ end
+ out << Maruku.new(noncode.join("\n")).to_html
+ out.join("\n")
+ end
+
+end
View
@@ -0,0 +1,13 @@
+# coding: utf-8
+#
+require 'ostruct'
+
+Setting = OpenStruct.new(
+ :title => "简单笔记",
+ :url_base => 'http://localhost:4567/',
+ :admin_password => 'change me',
+ :admin_cookie_key => 'note_admin',
+ :admin_cookie_value => '51d6d97fdsx36913ace58'
+ )
+
+

0 comments on commit 4f88b5e

Please sign in to comment.