asuka 0.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,25 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "Blockquote" do
4
+ describe "when it contains 1 line" do
5
+ before do
6
+ @lines = ["text"]
7
+ @blockquote = Asuka::Blockquote.new(@lines)
8
+ end
9
+
10
+ it "should convert to correct html" do
11
+ @blockquote.to_html.should == "<blockquote>text</blockquote>"
12
+ end
13
+ end
14
+
15
+ describe "when it contains many lines" do
16
+ before do
17
+ @lines = ["some","more","text"]
18
+ @blockquote = Asuka::Blockquote.new(@lines)
19
+ end
20
+
21
+ it "should convert to correct html (with <br/>)" do
22
+ @blockquote.to_html.should == "<blockquote>some<br/>\nmore<br/>\ntext</blockquote>"
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,59 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "Document" do
4
+ describe "when passing a parser" do
5
+ before do
6
+ @lines = ["some","more","text"]
7
+ @parser = mock
8
+ @document = Asuka::Document.new(@lines, @parser)
9
+ end
10
+
11
+ it "should delegate to parser" do
12
+ @parser.should_receive(:parse).with(@lines).and_return([])
13
+ @document.to_html
14
+ end
15
+ end
16
+
17
+ describe "when using the default parser" do
18
+ before do
19
+ @lines = ["some","more","text"]
20
+ @document = Asuka::Document.new(@lines)
21
+ end
22
+
23
+ it "should delegate to parser" do
24
+ @document.to_html.should == "<p>some<br/>\nmore<br/>\ntext</p>"
25
+ end
26
+ end
27
+
28
+ describe "when passing a customized parser" do
29
+ before do
30
+ @formatter = Asuka::Formatter.new
31
+ class << @formatter
32
+ def make_link(text, href, tags={})
33
+ tags = tags.merge(:href => href.strip)
34
+ tags[:target] = "_blank" if href !~ /^http:\/\/nowhere.com/
35
+
36
+ tags_to_attrs = tags.sort_by { |name, value| name.to_s }.
37
+ map { |name, value| %Q{ #{name}="#{value}"} }
38
+
39
+ "<a#{tags_to_attrs}>#{text.strip}</a>"
40
+ end
41
+ end
42
+
43
+ @line_formatter = Asuka::LineFormatter.new(@formatter)
44
+ @parser = Asuka::Parser.new(@line_formatter)
45
+ end
46
+
47
+ it "should not affect internal links" do
48
+ lines = ["some","more [internal link][http://nowhere.com] text"]
49
+ @document = Asuka::Document.new(lines, @parser)
50
+ @document.to_html.should == %Q{<p>some<br/>\nmore <a href="http://nowhere.com">internal link</a> text</p>}
51
+ end
52
+
53
+ it "should affect external links" do
54
+ lines = ["some","more [external link][http://somewhere.com] text"]
55
+ @document = Asuka::Document.new(lines, @parser)
56
+ @document.to_html.should == %Q{<p>some<br/>\nmore <a href="http://somewhere.com" target="_blank">external link</a> text</p>}
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,93 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ include Asuka
4
+
5
+ describe "Formatter" do
6
+ before do
7
+ @formatter = Formatter.new
8
+ end
9
+
10
+ describe "bold" do
11
+ it "applies bold format" do
12
+ @formatter.bold("a **delicious** pie").should == "a <strong>delicious</strong> pie"
13
+ end
14
+
15
+ it "disregards irrelevant spacing" do
16
+ @formatter.bold(" a ** delicious ** pie ").should == " a <strong> delicious </strong> pie "
17
+ end
18
+
19
+ it "doesn't get intercept italic" do
20
+ @formatter.bold("a *delicious* pie").should == "a *delicious* pie"
21
+ end
22
+
23
+ it "doesn't choke on unbalanced asterisks" do
24
+ @formatter.bold("a **delicious*** pie").should == "a <strong>delicious</strong>* pie"
25
+ @formatter.bold("a ***delicious** pie").should == "a *<strong>delicious</strong> pie"
26
+ end
27
+ end
28
+
29
+ describe "italic" do
30
+ it "applies italic format" do
31
+ @formatter.italic("a *delicious* pie").should == "a <em>delicious</em> pie"
32
+ end
33
+
34
+ it "disregards irrelevant spacing" do
35
+ @formatter.italic(" a * delicious * pie ").should == " a <em> delicious </em> pie "
36
+ end
37
+
38
+ it "doesn't mind bold" do
39
+ @formatter.italic("a **delicious** pie").should == "a *<em>delicious</em>* pie"
40
+ end
41
+
42
+ it "doesn't choke on unbalanced asterisks" do
43
+ @formatter.italic("a *delicious** pie").should == "a <em>delicious</em>* pie"
44
+ @formatter.italic("a **delicious* pie").should == "a *<em>delicious</em> pie"
45
+ end
46
+ end
47
+
48
+ describe "named_link" do
49
+ it "applies named_link format" do
50
+ result = "a <a href=\"http://delicious.com\">delicious</a> pie"
51
+ @formatter.named_link("a [delicious][http://delicious.com] pie").should == result
52
+ @formatter.named_link("a [http://delicious.com][delicious] pie").should == result
53
+ end
54
+
55
+ it "applies named_link format to https links" do
56
+ result = "a <a href=\"https://delicious.com\">delicious</a> pie"
57
+ @formatter.named_link("a [delicious][https://delicious.com] pie").should == result
58
+ @formatter.named_link("a [https://delicious.com][delicious] pie").should == result
59
+ end
60
+
61
+ it "applies named_link format (multi-words)" do
62
+ result = "a <a href=\"http://delicious.com\">very delicious</a> pie"
63
+ @formatter.named_link("a [very delicious][http://delicious.com] pie").should == result
64
+ @formatter.named_link("a [http://delicious.com][very delicious] pie").should == result
65
+ end
66
+
67
+ it "trims internal extra spacing" do
68
+ result = "a <a href=\"http://delicious.com\">delicious</a> pie"
69
+ @formatter.named_link("a [ delicious ][ http://delicious.com ] pie").should == result
70
+ @formatter.named_link("a [ http://delicious.com ][ delicious ] pie").should == result
71
+ end
72
+
73
+ it "ignores http:// if preceded by text" do
74
+ @formatter.named_link("a [delicious][link http://delicious.com] pie").should == "a [delicious][link http://delicious.com] pie"
75
+ @formatter.named_link("a [link http://delicious.com][delicious] pie").should == "a [link http://delicious.com][delicious] pie"
76
+ end
77
+
78
+ it "ignores http:// if followed by text" do
79
+ @formatter.named_link("a [delicious][http://delicious.com link] pie").should == "a [delicious][http://delicious.com link] pie"
80
+ @formatter.named_link("a [http://delicious.com link][delicious] pie").should == "a [http://delicious.com link][delicious] pie"
81
+ end
82
+
83
+ it "ignores javascript:// links" do
84
+ @formatter.named_link("a [delicious][javascript://delicious.com] pie").should == "a [delicious][javascript://delicious.com] pie"
85
+ @formatter.named_link("a [javascript://delicious.com][delicious] pie").should == "a [javascript://delicious.com][delicious] pie"
86
+ end
87
+
88
+ it "chokes on external extra spacing" do
89
+ @formatter.named_link("a [delicious] [http://delicious.com] pie").should == "a [delicious] [http://delicious.com] pie"
90
+ @formatter.named_link("a [http://delicious.com] [delicious] pie").should == "a [http://delicious.com] [delicious] pie"
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,12 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "Header" do
4
+ before do
5
+ @line = "text"
6
+ @header = Asuka::Header.new(@line, 2)
7
+ end
8
+
9
+ it "should convert to correct html" do
10
+ @header.to_html.should == "<h2>text</h2>"
11
+ end
12
+ end
@@ -0,0 +1,132 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "LineFormatter" do
4
+ before do
5
+ @formatter = Asuka::Formatter.new
6
+ end
7
+
8
+ describe "that is brand new" do
9
+ before do
10
+ @line = "a *magic* and **delicious** pie"
11
+ @formatter = stub
12
+ @lf = Asuka::LineFormatter.new(@formatter)
13
+ end
14
+
15
+ it "starts out empty" do
16
+ @lf.steps.should be_empty
17
+ end
18
+
19
+ it "should not apply any format" do
20
+ @lf.format(@line).should == @line
21
+ end
22
+ end
23
+
24
+ describe "that contains the default formatter" do
25
+ before do
26
+ @line = "a *magic* and **delicious** pie"
27
+ @lf = Asuka::LineFormatter.new(@formatter)
28
+ end
29
+
30
+ it "should import the formatter's default_steps" do
31
+ @lf.steps.size.should == @formatter.default_steps.size
32
+ end
33
+
34
+ it "should apply formats" do
35
+ @lf.format(@line).should == "a <em>magic</em> and <strong>delicious</strong> pie"
36
+ end
37
+ end
38
+
39
+ describe "with a custom rule" do
40
+ before do
41
+ @line = "a *magic* and **delicious** pie"
42
+
43
+ class << @formatter
44
+ def no_star(line)
45
+ line.gsub(/\*/, '')
46
+ end
47
+ end
48
+
49
+ @lf = Asuka::LineFormatter.new(@formatter, :no_star)
50
+ end
51
+
52
+ it "should have 1 rule" do
53
+ @lf.steps.size.should == 1
54
+ end
55
+
56
+ it "should apply that rule" do
57
+ @lf.format(@line).should == "a magic and delicious pie"
58
+ end
59
+ end
60
+
61
+ describe "with the bold rule" do
62
+ before do
63
+ @line = "a *magic* and **delicious** pie"
64
+ @lf = Asuka::LineFormatter.new(@formatter, :bold)
65
+ end
66
+
67
+ it "should apply bold format" do
68
+ @lf.format(@line).should == "a *magic* and <strong>delicious</strong> pie"
69
+ end
70
+
71
+ it "should not choke on bold party" do
72
+ line = "a ******magic and delicious****** pie"
73
+ @lf.format(line).should == "a ****<strong>magic and delicious</strong>**** pie"
74
+ end
75
+ end
76
+
77
+ describe "with the italic rule" do
78
+ before do
79
+ @line = "a *magic* and **delicious** pie"
80
+ @lf = Asuka::LineFormatter.new(@formatter, :italic)
81
+ end
82
+
83
+ it "should apply italic format" do
84
+ @lf.format(@line).should == "a <em>magic</em> and *<em>delicious</em>* pie"
85
+ end
86
+
87
+ it "should not choke on italic party" do
88
+ line = "a ******magic and delicious****** pie"
89
+ @lf.format(line).should == "a *****<em>magic and delicious</em>***** pie"
90
+ end
91
+ end
92
+
93
+ describe "the DEFAULT_LINE_FORMATTER one" do
94
+ before do
95
+ @line = "a *magic* and **delicious** pie"
96
+ @lf = Asuka::DEFAULT_LINE_FORMATTER
97
+ end
98
+
99
+ it "should not be empty" do
100
+ @lf.steps.should_not be_empty
101
+ end
102
+
103
+ it "should apply bold and italic format" do
104
+ @lf.format(@line).should == "a <em>magic</em> and <strong>delicious</strong> pie"
105
+ end
106
+
107
+ it "should apply bold_italic format" do
108
+ line = "a ***magic and delicious*** pie"
109
+ @lf.format(line).should == "a <em><strong>magic and delicious</strong></em> pie"
110
+ end
111
+
112
+ it "should apply named_link format" do
113
+ line = "a [magic and delicious][http://google.com] pie"
114
+ @lf.format(line).should == "a <a href=\"http://google.com\">magic and delicious</a> pie"
115
+ end
116
+ end
117
+
118
+ describe "the DEFAULT_PRE_LINE_FORMATTER one" do
119
+ before do
120
+ @line = " a magic & delicious pie > none "
121
+ @lf = Asuka::DEFAULT_PRE_LINE_FORMATTER
122
+ end
123
+
124
+ it "should not be empty" do
125
+ @lf.steps.should_not be_empty
126
+ end
127
+
128
+ it "should apply strip and html_escape" do
129
+ @lf.format(@line).should == "a magic &amp; delicious pie &gt; none"
130
+ end
131
+ end
132
+ end
@@ -0,0 +1,14 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "LineGroup" do
4
+ before do
5
+ @lines = ["some","text"]
6
+ @doc = Asuka::LineGroup.new(@lines)
7
+ end
8
+
9
+ it "doesn't allow to_html (abstract)" do
10
+ lambda {
11
+ @doc.to_html
12
+ }.should raise_error(NotImplementedError)
13
+ end
14
+ end
@@ -0,0 +1,25 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "Paragraph" do
4
+ describe "when it contains 1 line" do
5
+ before do
6
+ @lines = ["text"]
7
+ @paragraph = Asuka::Paragraph.new(@lines)
8
+ end
9
+
10
+ it "should convert to correct html" do
11
+ @paragraph.to_html.should == "<p>text</p>"
12
+ end
13
+ end
14
+
15
+ describe "when it contains many lines" do
16
+ before do
17
+ @lines = ["some","more","text"]
18
+ @paragraph = Asuka::Paragraph.new(@lines)
19
+ end
20
+
21
+ it "should convert to correct html (with <br/>)" do
22
+ @paragraph.to_html.should == "<p>some<br/>\nmore<br/>\ntext</p>"
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,11 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "Rule" do
4
+ before do
5
+ @rule = Asuka::Rule.new
6
+ end
7
+
8
+ it "should convert to correct html" do
9
+ @rule.to_html.should == "<hr/>"
10
+ end
11
+ end
@@ -0,0 +1,25 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "UnorderedList" do
4
+ describe "when it contains 1 line" do
5
+ before do
6
+ @lines = ["text"]
7
+ @list = Asuka::UnorderedList.new(@lines)
8
+ end
9
+
10
+ it "should convert to correct html" do
11
+ @list.to_html.should == "<ul>\n<li>text</li>\n</ul>"
12
+ end
13
+ end
14
+
15
+ describe "when it contains many lines" do
16
+ before do
17
+ @lines = ["some","more","text"]
18
+ @list = Asuka::UnorderedList.new(@lines)
19
+ end
20
+
21
+ it "should convert to correct html (with <br/>)" do
22
+ @list.to_html.should == "<ul>\n<li>some</li>\n<li>more</li>\n<li>text</li>\n</ul>"
23
+ end
24
+ end
25
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: asuka
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 5
8
+ - 3
9
+ version: 0.5.3
10
+ platform: ruby
11
+ authors:
12
+ - Jonathan Palardy
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-04-15 00:00:00 -07:00
18
+ default_executable: asuka
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 2
30
+ - 9
31
+ version: 1.2.9
32
+ type: :development
33
+ version_requirements: *id001
34
+ description: Markdown and textile -inspired markup that's XSS safe.
35
+ email: jonathan@fetlife.com
36
+ executables:
37
+ - asuka
38
+ extensions: []
39
+
40
+ extra_rdoc_files:
41
+ - LICENSE
42
+ - README.rdoc
43
+ files:
44
+ - .document
45
+ - .gitignore
46
+ - LICENSE
47
+ - README.rdoc
48
+ - Rakefile
49
+ - VERSION
50
+ - bin/asuka
51
+ - lib/asuka.rb
52
+ - lib/asuka/accumulator.rb
53
+ - lib/asuka/document.rb
54
+ - lib/asuka/formatter.rb
55
+ - lib/asuka/line_formatter.rb
56
+ - lib/asuka/parser.rb
57
+ - lib/asuka/rules.rb
58
+ - samples/samples.asuka
59
+ - spec/integration/parser_spec.rb
60
+ - spec/spec.opts
61
+ - spec/spec_helper.rb
62
+ - spec/unit/accumulator_spec.rb
63
+ - spec/unit/blockquote_spec.rb
64
+ - spec/unit/document_spec.rb
65
+ - spec/unit/formatter_spec.rb
66
+ - spec/unit/header_spec.rb
67
+ - spec/unit/line_formatter_spec.rb
68
+ - spec/unit/line_group_spec.rb
69
+ - spec/unit/paragraph_spec.rb
70
+ - spec/unit/rule_spec.rb
71
+ - spec/unit/unordered_list_spec.rb
72
+ has_rdoc: true
73
+ homepage: http://fetlife.com
74
+ licenses: []
75
+
76
+ post_install_message:
77
+ rdoc_options:
78
+ - --charset=UTF-8
79
+ require_paths:
80
+ - lib
81
+ required_ruby_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ segments:
86
+ - 0
87
+ version: "0"
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ segments:
93
+ - 0
94
+ version: "0"
95
+ requirements: []
96
+
97
+ rubyforge_project:
98
+ rubygems_version: 1.3.6
99
+ signing_key:
100
+ specification_version: 3
101
+ summary: Safe and pleasant text-to-HTML converter.
102
+ test_files:
103
+ - spec/integration/parser_spec.rb
104
+ - spec/spec_helper.rb
105
+ - spec/unit/accumulator_spec.rb
106
+ - spec/unit/blockquote_spec.rb
107
+ - spec/unit/document_spec.rb
108
+ - spec/unit/formatter_spec.rb
109
+ - spec/unit/header_spec.rb
110
+ - spec/unit/line_formatter_spec.rb
111
+ - spec/unit/line_group_spec.rb
112
+ - spec/unit/paragraph_spec.rb
113
+ - spec/unit/rule_spec.rb
114
+ - spec/unit/unordered_list_spec.rb