hemingway 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,6 +11,8 @@ module Hemingway
11
11
  tag_start hfill spaces sequence:( !newline content )* <HFillNode>
12
12
  /
13
13
  tag_start neatline <NeatLineNode>
14
+ /
15
+ tag_start accent "{" character:. "}" <AccentNode>
14
16
  end
15
17
 
16
18
  # All tag types will be responsible with implementing their own
@@ -51,6 +53,10 @@ module Hemingway
51
53
  "neatline"
52
54
  end
53
55
 
56
+ rule accent
57
+ '`' / "'" / '^' / '"' / "c" / "~" / "r"
58
+ end
59
+
54
60
  rule tag_start
55
61
  "\\"
56
62
  end
@@ -46,4 +46,10 @@ module Hemingway
46
46
  Build.tag("span", content, :class => "textsc")
47
47
  end
48
48
  end
49
+
50
+ module AccentNode
51
+ def html
52
+ Build.accent(character.text_value, accent.text_value)
53
+ end
54
+ end
49
55
  end
@@ -1,3 +1,3 @@
1
1
  module Hemingway
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/spec/build_spec.rb CHANGED
@@ -39,6 +39,10 @@ module Hemingway
39
39
  Build.tag(attribute, content, :id => id, :class => klass, :href => href).should == "<#{attribute} id='#{id}' class='#{klass}' href='#{href}'>#{content}</#{attribute}>"
40
40
  end
41
41
 
42
+ it 'should generate a tag with content and a src and no closing tag' do
43
+ Build.tag("img", nil, :src => "/assets/vibes.png", :close_tag => false).should == "<img src='/assets/vibes.png'>"
44
+ end
45
+
42
46
  # Can't wait for Ruby 2.0
43
47
  it 'should generate a tag with content and a class and no content' do
44
48
  Build.tag(attribute, nil, :class => klass).should == "<#{attribute} class='#{klass}'></#{attribute}>"
@@ -60,6 +64,19 @@ module Hemingway
60
64
 
61
65
  end
62
66
 
67
+ describe "#accent" do
68
+
69
+ it 'should convert an accent and character into the html equivalent' do
70
+ Build.accent("A", "`").should == "&Agrave;"
71
+ end
72
+
73
+ it 'should leave the character untouched if no equiavalent exists' do
74
+ Build.accent("G", "`").should == "G"
75
+ Build.accent("C", "~").should == "C"
76
+ end
77
+
78
+ end
79
+
63
80
  end
64
81
 
65
82
  end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ module Hemingway
4
+
5
+ describe Parser do
6
+
7
+ before do
8
+ @parser = Parser.new
9
+ end
10
+
11
+ describe "#center" do
12
+
13
+ it 'centers text' do
14
+ html = @parser.parse("\\begin{center} So show my why you're strong. \n\n Ignore everybody else \n\n We're alone now \\end{center}").html
15
+ html.should == "<div class='entry'><p><div class='center'>So show my why you're strong. \n\n Ignore everybody else \n\n We're alone now </div></p></div>"
16
+ end
17
+
18
+ it 'centers content too' do
19
+ html = @parser.parse("The New James Blake: \\begin{center} So show my why you're \\emph{strong}. \n\n Ignore \\textsc{everybody} else \n\n We're alone now \\end{center}").html
20
+ html.should == "<div class='entry'><p>The New James Blake: <div class='center'>So show my why you're <em>strong</em>. \n\n Ignore <span class='textsc'>everybody</span> else \n\n We're alone now </div></p></div>"
21
+ end
22
+
23
+ end
24
+
25
+ end
26
+
27
+ end
@@ -60,6 +60,11 @@ module Hemingway
60
60
  html.should == "<div class='entry'><p><ul><li><ul><li><ul><li>hey </li></ul> </li></ul> </li></ul></p></div>"
61
61
  end
62
62
 
63
+ it 'allows me to created a nested list without specfying another item' do
64
+ html = @parser.parse("\\begin{itemize} \n \\item thing 1 \n \\begin{itemize} \n \\item 2 \n \\end{itemize} \n \\end{itemize}").html
65
+ html.should == "<div class='entry'><p><ul><li>thing 1 <ul><li>2 </li></ul> </li></ul></p></div>"
66
+ end
67
+
63
68
  end
64
69
 
65
70
  describe "#enumerate" do
@@ -14,8 +14,12 @@ module Hemingway
14
14
  @parser.parse("\\begin{itemize} \\item hey \\end{description}").should be_nil
15
15
  end
16
16
 
17
- end
17
+ it "should allow me to put blocks right after text and a newline" do
18
+ html = @parser.parse("check out this f*ckin block:\n\\begin{itemize} \\item hey \\end{itemize}").html
19
+ html.should == "<div class='entry'><p>check out this f*ckin block:<ul><li>hey </li></ul></p></div>"
20
+ end
18
21
 
22
+ end
19
23
  end
20
24
  end
21
25
 
@@ -24,6 +24,16 @@ module Hemingway
24
24
  html.should == "<div class='entry'><p>hello &Delta;</p></div>"
25
25
  end
26
26
 
27
+ it 'should allow me to exponentiate text' do
28
+ html = @parser.parse("December 7$^{th}$").html
29
+ html.should == "<div class='entry'><p>December 7<sup>th</sup></p></div>"
30
+ end
31
+
32
+ it 'should allow me to make a degree sign' do
33
+ html = @parser.parse("25 $^{\\circ}$ celcius").html
34
+ html.should == "<div class='entry'><p>25 &deg; celcius</p></div>"
35
+ end
36
+
27
37
  end
28
38
 
29
39
  end
@@ -15,6 +15,12 @@ module Hemingway
15
15
  html.should == "<div class='entry'><p>War & Peace</p></div>"
16
16
  end
17
17
 
18
+ it 'should escape a special backslash character' do
19
+ html = @parser.parse("\\textbackslash{}part").html
20
+ html.should == "<div class='entry'><p>\\part</p></div>"
21
+ end
22
+
23
+
18
24
  it 'should allow for special chars and tags in sequence' do
19
25
  html = @parser.parse("War \\& Peace \\textbf{Tolstoy} \\#").html
20
26
  html.should == "<div class='entry'><p>War & Peace <strong>Tolstoy</strong> #</p></div>"
@@ -93,6 +93,15 @@ module Hemingway
93
93
 
94
94
  end
95
95
 
96
+ describe "#accents" do
97
+
98
+ it 'allows me to put accents inline with text' do
99
+ html = @parser.parse("Charm\\'{e}e de vous voir. Je suis tr\\`{e} contente de vous voir.").html
100
+ html.should == "<div class='entry'><p>Charm&eacute;e de vous voir. Je suis tr&egrave; contente de vous voir.</p></div>"
101
+ end
102
+
103
+ end
104
+
96
105
  end
97
106
 
98
107
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hemingway
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Myers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-21 00:00:00.000000000 Z
11
+ date: 2013-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -56,6 +56,9 @@ files:
56
56
  - lib/hemingway/block/block.rb
57
57
  - lib/hemingway/block/block.treetop
58
58
  - lib/hemingway/block/block_nodes.rb
59
+ - lib/hemingway/block/center/center.rb
60
+ - lib/hemingway/block/center/center.treetop
61
+ - lib/hemingway/block/center/center_nodes.rb
59
62
  - lib/hemingway/block/list/list.rb
60
63
  - lib/hemingway/block/list/list.treetop
61
64
  - lib/hemingway/block/list/list_nodes.rb
@@ -91,6 +94,7 @@ files:
91
94
  - script/build
92
95
  - script/test
93
96
  - spec/build_spec.rb
97
+ - spec/nodes/block/center_spec.rb
94
98
  - spec/nodes/block/list_spec.rb
95
99
  - spec/nodes/block/quote_spec.rb
96
100
  - spec/nodes/block/verbatim_spec.rb
@@ -127,6 +131,7 @@ specification_version: 4
127
131
  summary: Hemingway is a LaTeX to HTML parser.
128
132
  test_files:
129
133
  - spec/build_spec.rb
134
+ - spec/nodes/block/center_spec.rb
130
135
  - spec/nodes/block/list_spec.rb
131
136
  - spec/nodes/block/quote_spec.rb
132
137
  - spec/nodes/block/verbatim_spec.rb