Permalink
Browse files

Repo init, Dtext re-implementation attempt.

  • Loading branch information...
0 parents commit 2755a1673e272c237a62a3abafaf5de6c60d39f7 @fudanchii fudanchii committed May 9, 2012
Showing with 102 additions and 0 deletions.
  1. +1 −0 .hgignore
  2. +1 −0 .rspec
  3. +4 −0 Gemfile
  4. +8 −0 Rakefile
  5. +27 −0 lib/dtext.rb
  6. +54 −0 spec/dtext_spec.rb
  7. +7 −0 spec/helper.rb
@@ -0,0 +1 @@
+Gemfile.lock$
1 .rspec
@@ -0,0 +1 @@
+-c -f documentation
@@ -0,0 +1,4 @@
+source 'https://rubygems.org'
+gem "rake"
+gem "rspec"
+gem "nokogiri"
@@ -0,0 +1,8 @@
+require 'rspec/core/rake_task'
+
+desc 'Default: run specs.'
+task :default => :spec
+
+desc "Run specs"
+RSpec::Core::RakeTask.new do |t|
+end
@@ -0,0 +1,27 @@
+require 'nokogiri'
+
+module DText
+ def parse(str)
+ # split str into lines (separated by single new line)
+ # prepare state stack
+ # start from empty state
+
+ state = []
+
+ # Normalize newlines
+ str.gsub(/(\r?\n){3,}/m, "\n\n")
+
+ data = str.split("\n")
+
+ data.each do |d|
+
+ end
+
+ end
+
+ def parseline( )
+
+ str.gsub(/^(h[1-6])\.\s+(.+)\n*/m, '<\1>\2</\1>')
+ end
+
+end
@@ -0,0 +1,54 @@
+require 'helper.rb'
+
+describe "Header" do
+
+ it "- should acknowledge h1 to h6" do
+ (1..6).each { |i|
+ p("h#{i}. header").should eq("<h#{i}>header</h#{i}>")
+ }
+ end
+
+ it "- for each tag, should separated by at least a single newline" do
+ p("h1. header1\nh2. header2\nh3. header3").should(
+ eq("<h1>header1</h1><h2>header2</h2><h3>header3</h3>")
+ )
+ p("h1. header1\n\n\nh2. header2\n\nh3. header3").should(
+ eq("<h1>header1</h1><h2>header2</h2><h3>header3</h3>")
+ )
+ end
+
+ it "- not an inline tag" do
+ p("start h1. paragraph no header").should eq "<p>start h1. paragraph no header</p>"
+ end
+end
+
+
+describe "List" do
+end
+
+
+describe "Paragraph" do
+end
+
+
+describe "Link" do
+end
+
+
+describe "Spoiler" do
+end
+
+
+describe "Special chars" do
+ it "- '>' translates to &gt;" do
+ p(">").should eq "<p>&gt;</p>"
+ end
+
+ it "- '<' translates to &lt;" do
+ p("<").should eq "<p>&lt;</p>"
+ end
+
+ it "- '&' translates to &amp;" do
+ p("&").should eq "<p>&amp;</p>"
+ end
+end
@@ -0,0 +1,7 @@
+require './lib/dtext.rb'
+
+include DText
+
+def p(str)
+ DText.parse(str)
+end

0 comments on commit 2755a16

Please sign in to comment.