poppins 0.0.2 → 0.0.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.
data/CHANGES.md ADDED
@@ -0,0 +1,6 @@
1
+ # Changelog for Poppins
2
+
3
+ ## 0.0.3 (15oct2012)
4
+
5
+ - Resolved akmassey/poppins#1
6
+
data/Guardfile ADDED
@@ -0,0 +1,24 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'rspec' do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+
9
+ # Rails example
10
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
11
+ watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
12
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
13
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
14
+ watch('config/routes.rb') { "spec/routing" }
15
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
16
+
17
+ # Capybara request specs
18
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
19
+
20
+ # Turnip features and steps
21
+ watch(%r{^spec/acceptance/(.+)\.feature$})
22
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
23
+ end
24
+
data/README.md CHANGED
@@ -36,7 +36,17 @@ Or install it yourself as:
36
36
 
37
37
  ## Roadmap
38
38
 
39
- Poppins is intended to be similar to [formd](http://www.drbunsen.org/formd-a-markdown-formatting-tool.html), but with easier integration with Ruby projects. Also, I would like to add the ability to insert reference links they way Dr. Drang describes [here](http://www.leancrew.com/all-this/2012/08/markdown-reference-links-in-bbedit/) and [here](http://www.leancrew.com/all-this/2012/08/more-markdown-reference-links-in-bbedit/).
39
+ Poppins is intended to be similar to [formd][2], but with easier
40
+ integration with Ruby projects. Also, I would like to add the ability
41
+ to insert reference links they way Dr. Drang describes
42
+ [here](http://www.leancrew.com/all-this/2012/08/markdown-reference-links-in-bbedit/)
43
+ and [here][3].
44
+
45
+ It would also be really awesome if we could re-flow paragraph text and
46
+ wrap it at user-specified column lengths.
47
+
48
+ Currently, Poppins doesn't handle implicit reference links. Those are
49
+ links that look [like this] or perhaps [like this][].
40
50
 
41
51
 
42
52
  ## Contributing
@@ -48,5 +58,9 @@ Poppins is intended to be similar to [formd](http://www.drbunsen.org/formd-a-mar
48
58
  5. Create new Pull Request
49
59
 
50
60
 
61
+
51
62
  [1]: http://www.leancrew.com/all-this/2012/09/tidying-markdown-reference-links/
63
+ [2]: http://www.drbunsen.org/formd-a-markdown-formatting-tool.html
64
+ [3]: http://www.leancrew.com/all-this/2012/08/more-markdown-reference-links-in-bbedit/
52
65
 
66
+ [like this]: http://google.com
data/bin/poppins CHANGED
@@ -36,5 +36,9 @@ input = ARGV.shift.to_s.strip
36
36
 
37
37
  poppins = Poppins::Document.new input, @output
38
38
 
39
- poppins.clean_and_format
39
+ puts poppins.clean_and_format
40
+
41
+ # puts poppins.convert_inline_to_reference
42
+
43
+ # puts poppins.convert_reference_to_inline
40
44
 
data/lib/poppins.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  require_relative "poppins/version"
2
2
  require_relative "poppins/document"
3
+ require_relative "poppins/reference_link"
4
+ require_relative "poppins/inline_link"
3
5
 
4
6
  module Poppins
5
7
  # Your code goes here...
@@ -1,9 +1,14 @@
1
+ require 'securerandom'
2
+ require_relative 'reference_link'
3
+ require_relative 'inline_link'
4
+
1
5
  module Poppins
2
6
  class Document
7
+ attr_reader :reference_links, :inline_links, :links
3
8
 
4
9
  def initialize(input=nil, output=nil)
5
10
  if input.empty?
6
- # TODO: Probably need to raise an error if ARGF is nil...
11
+ raise "invalid input" unless (ARGF.respond_to?(:readlines) and not ARGF.nil?)
7
12
  @input = ARGF.readlines.join
8
13
  else
9
14
  @input = File.open(input, 'r').readlines.join
@@ -11,82 +16,127 @@ module Poppins
11
16
 
12
17
  @output = output
13
18
 
14
- # RegEx for matching reference links in the text. (Avoid footnotes!)
15
- @links = /\[([^\]]+)\]\[([^^\]]+)\]/
16
- # RegEx for matching labels for reference links. (Avoid footnotes!)
17
- @labels = /^\[([^^\]]+)\]:\s+(.+)$/
18
- @labels_with_possible_newlines = /^\[([^^\]]+)\]:\s+(.+)(\n)?/
19
+ identify_inline_links
20
+ identify_reference_links
19
21
  end
20
22
 
21
- ##
22
- # Returns an array of the links found in the document in order.
23
- def links
24
- @input.scan(@links)
25
- end
26
23
 
27
- def labels
28
- Hash[@input.scan(@labels)]
29
- end
24
+ ##
25
+ # Identifies inline links in the document
26
+ def identify_inline_links(input=@input)
27
+ inline_links = Hash[input.scan(InlineLink.inline_regex)]
30
28
 
31
- def order_of_first_appearance
32
- order = []
33
- links.each do |l|
34
- order.push(l[1]) unless order.include?(l[1])
29
+ @inline_links = []
30
+
31
+ inline_links.each do |il|
32
+ @inline_links.push( InlineLink.new(il.to_a[1], il.to_a[0]) )
35
33
  end
36
34
 
37
- order
35
+ @inline_links
38
36
  end
39
37
 
40
- def ordinal_references
41
- references = []
42
- order_of_first_appearance.each_with_index do |o, i|
43
- references.push("[#{i+1}]: #{labels[o]}")
44
- end
38
+ ##
39
+ # Identifies reference links in the document
40
+ def identify_reference_links(input=@input)
41
+ reference_links = Hash[input.scan(ReferenceLink.link_regex)]
45
42
 
46
- references
47
- end
43
+ labels = Hash[input.scan(ReferenceLink.label_regex)]
48
44
 
49
- ##
50
- # Returns an array of the link text and the new reference number when
51
- # passed links based on the old reference numbering system
52
- def get_replacement(string)
53
- md = string.match(@links)
54
- link_text = md[1].to_s
55
- reference_number = (order_of_first_appearance.index(md[2]) + 1).to_s
56
-
57
- return [link_text, reference_number]
45
+ @reference_links = []
46
+
47
+ reference_links.each do |rl|
48
+ @reference_links.push( ReferenceLink.new(labels[rl.to_a[1]], rl.to_a[0], rl.to_a[1] ) )
49
+ end
50
+
51
+ # Note that the order of the links in this list is the same as their
52
+ # appearance in the text.
53
+ @reference_links
58
54
  end
59
55
 
60
56
 
61
57
  ##
62
58
  # Produces the clean, formatted version of the Markdown with new
63
59
  # reference numbers.
64
- def clean_and_format
65
- # Remove old references (TOOD: Need to remove blank lines resulting from
66
- # this.)
67
- result = @input.gsub(@labels_with_possible_newlines, '')
68
- #
69
- # Add new references
70
- ordinal_references.each do |r|
71
- result += r.to_s + "\n"
60
+ def clean_and_format(input=@input)
61
+ result = input
62
+ result = convert_reference_to_inline(result)
63
+ result = convert_inline_to_reference(result)
64
+
65
+ identify_reference_links(result)
66
+
67
+ # Remove old reference labels from the end
68
+ # TODO: This currently destroys links that don't appear anywhere else in
69
+ # the text since they aren't added back in unless they were used in the
70
+ # text..
71
+ result = result.gsub(ReferenceLink.label_regex_with_possible_newlines, '')
72
+
73
+ # Add new reference labels to the end
74
+ @reference_links.each_with_index do |rl, i|
75
+ result += "[#{i+1}]: #{rl.url}\n"
72
76
  end
73
77
 
74
78
  # Replace old reference numbers with the new ones
75
- result = result.gsub(@links) do |m|
76
- replacement = get_replacement(m)
77
- "[#{replacement[0]}][#{replacement[1]}]"
78
- end
79
+ result = result.gsub(ReferenceLink.link_regex) do |match|
80
+ # TODO: There has to be a cleaner way to do this...
81
+ match_data = match.match(ReferenceLink.link_regex)
79
82
 
80
- # output the result
81
- # puts result
83
+ link_text = match_data[1].to_s
84
+ label_from_match = match_data[2].to_s
85
+ new_label = @reference_links.index { |rl| rl.label == label_from_match }
82
86
 
87
+ # TODO: Do you really want to strip whitespace here?
88
+ "[#{link_text.strip}][#{new_label + 1}]"
89
+ end
90
+
91
+ # return the result
83
92
  if @output
84
93
  File.open(@output, 'w') do |f|
85
94
  f.write(result)
86
95
  end
87
- else
88
- puts result
89
96
  end
97
+
98
+ result
99
+ end
100
+
101
+ ##
102
+ # Produces a clean, formatted version of the Markdown while also
103
+ # converting inline links to reference links.
104
+ def convert_inline_to_reference(input=@input)
105
+ result = input
106
+ identify_inline_links(result)
107
+
108
+ @inline_links.each do |link|
109
+ reference_label = SecureRandom.hex(8)
110
+ result = result.gsub(link.regex) do |match|
111
+ "[#{link.link_text}][#{reference_label}]"
112
+ end
113
+ result += "[#{reference_label}]: #{link.url}\n"
114
+ end
115
+
116
+ result
117
+ end
118
+
119
+ ##
120
+ # Convert reference links to inline links. This can be used prior to
121
+ # converting back to reference links to ensure that all links are
122
+ # reference links and they are numbered in the order they appear.
123
+ def convert_reference_to_inline(input=@input)
124
+ result = input
125
+
126
+ # TODO: Should DRY this
127
+ labels = Hash[input.scan(ReferenceLink.label_regex)]
128
+ ref_urls = labels.values
129
+
130
+ ref_urls.each do |url|
131
+ regex = /\[([^\]]+)\]\[(#{Regexp.quote(url)})\]/
132
+ result = result.gsub(regex) do |match|
133
+ "[#{match[1]}](#{url})"
134
+ end
135
+ end
136
+
137
+ # TODO: Need to be able to store this separately if they want to have
138
+ # inline links only.
139
+ result
90
140
  end
91
141
  end
92
142
  end
@@ -0,0 +1,34 @@
1
+ module Poppins
2
+ class InlineLink
3
+ # RegEx for matching inline links in the text.
4
+ @inline_regex = /\[([^\]]+)\]\(([^\)]+)\)/
5
+
6
+ attr_reader :url
7
+ attr_accessor :link_text, :reference_label
8
+
9
+ def initialize(url, link_text)
10
+ @url = url
11
+ @link_text = link_text
12
+ end
13
+
14
+ def self.inline_regex
15
+ @inline_regex
16
+ end
17
+
18
+ def as_found_in_text
19
+ "[#{@link_text}](#{@url})"
20
+ end
21
+
22
+ def to_s
23
+ as_found_in_text
24
+ end
25
+
26
+ ##
27
+ # Returns a regular expression that can be used to find examples of this
28
+ # link in a sample text.
29
+ def regex
30
+ /\[([^\]]+)\]\((#{Regexp.quote(@url)})\)/
31
+ end
32
+ end
33
+ end
34
+
@@ -0,0 +1,41 @@
1
+ module Poppins
2
+ class ReferenceLink
3
+ # RegEx for matching reference links in the text. (Avoid footnotes!)
4
+ @link_regex = /\[([^\]]+)\]\[([^^\]]+)\]/
5
+ # RegEx for matching labels for reference links. (Avoid footnotes!)
6
+ @label_regex = /^\[([^^\]]+)\]:\s+(.+)$/
7
+ @label_regex_with_possible_newlines = /^\[([^^\]]+)\]:\s+(.+)(\n)?/
8
+
9
+ attr_reader :url, :link_text, :label, :link_regex, :label_regex
10
+
11
+ def initialize(url="", link_text="", label="")
12
+ @url = url
13
+ @link_text = link_text
14
+ @label = label
15
+ end
16
+
17
+ def self.link_regex
18
+ @link_regex
19
+ end
20
+
21
+ def self.label_regex
22
+ @label_regex
23
+ end
24
+
25
+ def self.label_regex_with_possible_newlines
26
+ @label_regex_with_possible_newlines
27
+ end
28
+
29
+ def as_end_reference
30
+ "[#{@link_text}]: #{@url}"
31
+ end
32
+
33
+ def as_found_in_text
34
+ "[#{@link_text}]"
35
+ end
36
+
37
+ def to_s
38
+ "[#{@label}]: #{@url}, found for text: #{@link_text}\n"
39
+ end
40
+ end
41
+ end
@@ -1,3 +1,3 @@
1
1
  module Poppins
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/poppins.gemspec CHANGED
@@ -17,4 +17,5 @@ Gem::Specification.new do |gem|
17
17
 
18
18
 
19
19
  gem.add_development_dependency 'rspec'
20
+ gem.add_development_dependency 'guard-rspec'
20
21
  end
@@ -0,0 +1,25 @@
1
+ Species and their hybrids, How simply are these facts! How strange that
2
+ the pollen of each But we may thus have
3
+ [succeeded][1] in selecting so many exceptions to
4
+ this rule. but the species would not all the same species living on the
5
+ White Mountains, in the arctic regions of that large island. The
6
+ exceptions which are now large, and triumphant, and which are known to
7
+ every naturalist: scarcely a single [character][2]
8
+ in the descendants of the Glacial period, would have been of use to the
9
+ plants, have been accumulated and if, in both regions.
10
+
11
+ Supposed to be extinct and unknown, form. We have seen that it yields
12
+ readily, when subjected as [under
13
+ confinement][3], to new and
14
+ improved varieties will have been much compressed, we may assume that
15
+ the species, which are already present in the ordinary spines serve as a
16
+ prehensile or snapping apparatus. Thus every gradation, from animals
17
+ with true lungs are descended from a marsupial form), "and if so, there
18
+ can be followed by which viscid matter, such as that of making
19
+ [slaves][4]. Let it be remembered that
20
+ selection may be extended--to the stigma of.
21
+
22
+ [1]: http://www.google.com
23
+ [2]: http://kungfugrippe.com
24
+ [3]: http://docs.python.org/library/index.html
25
+ [4]: http://daringfireball.net/markdown
@@ -0,0 +1,23 @@
1
+ Species and their hybrids, How simply are these facts! How strange that
2
+ the pollen of each But we may thus have [succeeded] in selecting so
3
+ many exceptions to this rule. but the species would not all the same
4
+ species living on the White Mountains, in the arctic regions of that
5
+ large island. The [exceptions which](http://github.com) are now large,
6
+ and triumphant, and which are known to every naturalist: scarcely a
7
+ single [character][4] in the descendants of the Glacial period, would
8
+ have been of use to the plants, have been accumulated and if, in both
9
+ regions.
10
+
11
+ Supposed to be extinct and unknown, form. We have seen that it yields
12
+ readily, when subjected as [under confinement], to new and improved
13
+ varieties will have been much compressed, we [may assume](http://blaynesucks.com) that the species, which are already
14
+ present in the ordinary spines serve as a prehensile or snapping
15
+ apparatus. Thus every gradation, from animals with true lungs are
16
+ descended from a marsupial form), "and if so, there can be followed by
17
+ which viscid matter, such as that of making [slaves][1]. Let it be
18
+ remembered that selection may be extended--to the stigma of.
19
+
20
+ [1]: http://daringfireball.net/markdown/
21
+ [succeeded]: http://www.google.com/
22
+ [under confinement]: http://docs.python.org/library/index.html
23
+ [4]: http://www.kungfugrippe.com/
@@ -0,0 +1,13 @@
1
+ ## Roadmap
2
+
3
+ Poppins is intended to be similar to [formd][2], but with easier
4
+ integration with Ruby projects. Also, I would like to add the ability
5
+ to insert reference links they way Dr. Drang describes
6
+ [here](http://www.leancrew.com/all-this/2012/08/markdown-reference-links-in-bbedit/)
7
+ and [here][3].
8
+
9
+ It would also be really awesome if we could re-flow paragraph text and
10
+ wrap it at user-specified column lengths.
11
+
12
+ [2]: http://www.drbunsen.org/formd-a-markdown-formatting-tool.html
13
+ [3]: http://www.leancrew.com/all-this/2012/08/more-markdown-reference-links-in-bbedit/
@@ -0,0 +1,23 @@
1
+ Species and their hybrids, How simply are these facts! How strange that
2
+ the pollen of each But we may thus have [succeeded][2] in selecting so
3
+ many exceptions to this rule. but the species would not all the same
4
+ species living on the White Mountains, in the arctic regions of that
5
+ large island. The [exceptions which](http://github.com) are now large,
6
+ and triumphant, and which are known to every naturalist: scarcely a
7
+ single [character][4] in the descendants of the Glacial period, would
8
+ have been of use to the plants, have been accumulated and if, in both
9
+ regions.
10
+
11
+ Supposed to be extinct and unknown, form. We have seen that it yields
12
+ readily, when subjected as [under confinement][3], to new and improved
13
+ varieties will have been much compressed, we [may assume](http://blaynesucks.com) that the species, which are already
14
+ present in the ordinary spines serve as a prehensile or snapping
15
+ apparatus. Thus every gradation, from animals with true lungs are
16
+ descended from a marsupial form), "and if so, there can be followed by
17
+ which viscid matter, such as that of making [slaves][1]. Let it be
18
+ remembered that selection may be extended--to the stigma of.
19
+
20
+ [1]: http://daringfireball.net/markdown/
21
+ [2]: http://www.google.com/
22
+ [3]: http://docs.python.org/library/index.html
23
+ [4]: http://www.kungfugrippe.com/
data/spec/data/sample.md CHANGED
@@ -20,7 +20,7 @@ if so, there can be followed by which viscid matter, such as
20
20
  that of making [slaves][1]. Let it be remembered that
21
21
  selection may be extended--to the stigma of.
22
22
 
23
- [1]: http://daringfireball.net/markdown/
24
- [2]: http://www.google.com/
23
+ [1]: http://daringfireball.net/markdown
24
+ [2]: http://www.google.com
25
25
  [3]: http://docs.python.org/library/index.html
26
- [4]: http://www.kungfugrippe.com/
26
+ [4]: http://www.kungfugrippe.com
@@ -0,0 +1,21 @@
1
+ Species and their hybrids, How simply are these facts! How strange that
2
+ the pollen of each But we may thus have
3
+ [succeeded](http://www.google.com) in selecting so many exceptions to
4
+ this rule. but the species would not all the same species living on the
5
+ White Mountains, in the arctic regions of that large island. The
6
+ exceptions which are now large, and triumphant, and which are known to
7
+ every naturalist: scarcely a single [character](http://kungfugrippe.com)
8
+ in the descendants of the Glacial period, would have been of use to the
9
+ plants, have been accumulated and if, in both regions.
10
+
11
+ Supposed to be extinct and unknown, form. We have seen that it yields
12
+ readily, when subjected as [under
13
+ confinement](http://docs.python.org/library/index.html), to new and
14
+ improved varieties will have been much compressed, we may assume that
15
+ the species, which are already present in the ordinary spines serve as a
16
+ prehensile or snapping apparatus. Thus every gradation, from animals
17
+ with true lungs are descended from a marsupial form), "and if so, there
18
+ can be followed by which viscid matter, such as that of making
19
+ [slaves](http://daringfireball.net/markdown). Let it be remembered that
20
+ selection may be extended--to the stigma of.
21
+
@@ -1,28 +1,63 @@
1
1
  require 'spec_helper'
2
+ module Poppins
2
3
 
3
- describe Poppins::Document do
4
+ describe Document do
4
5
 
5
- before do
6
- @file = File.dirname(__FILE__) + '/../data/sample.md'
7
- end
6
+ before do
7
+ @file = File.dirname(__FILE__) + '/../data/sample.md'
8
+ @clean_file = File.dirname(__FILE__) + '/../data/clean_formatted_sample.md'
9
+ @inline_file = File.dirname(__FILE__) + '/../data/sample_inline.md'
10
+ end
8
11
 
9
- it "should be instantiatable" do
10
- Poppins::Document.new(@file).should_not be_nil
11
- end
12
+ it "should be instantiatable" do
13
+ Document.new(@file).should_not be_nil
14
+ end
12
15
 
13
- it "should accurately identify links in the text" do
14
- Poppins::Document.new(@file).links.should == [["succeeded", "2"], ["character", "4"], ["under confinement", "3"], ["slaves", "1"]]
15
- end
16
+ it "should accurately identify inline links in the text" do
17
+ expected_ils = []
18
+ expected_ils.push( InlineLink.new("http://www.google.com", "succeeded") )
19
+ expected_ils.push( InlineLink.new("http://kungfugrippe.com", "character") )
20
+ expected_ils.push( InlineLink.new("http://docs.python.org/library/index.html", "under\nconfinement") )
21
+ expected_ils.push( InlineLink.new("http://daringfireball.net/markdown", "slaves") )
16
22
 
17
- it "should accuaretely identify a hash of the references" do
18
- Poppins::Document.new(@file).labels.should == {"1"=>"http://daringfireball.net/markdown/", "2"=>"http://www.google.com/", "3"=>"http://docs.python.org/library/index.html", "4"=>"http://www.kungfugrippe.com/"}
19
- end
23
+ actual_ils = Document.new(@inline_file).inline_links
20
24
 
21
- it "should correctly idenfity the order of the links as they appear in the text" do
22
- Poppins::Document.new(@file).order_of_first_appearance.should == ["2", "4", "3", "1"]
23
- end
25
+ actual_ils.count.should == 4
26
+
27
+ for i in 0..(actual_ils.count-1)
28
+ actual_ils[i].to_s.should == expected_ils[i].to_s
29
+ end
30
+ end
31
+
32
+ it "should accurately identify reference links in the text" do
33
+ expected_rls = []
34
+
35
+ expected_rls.push( ReferenceLink.new("http://www.google.com", "succeeded", "2") )
36
+ expected_rls.push( ReferenceLink.new("http://www.kungfugrippe.com", "character", "4") )
37
+ expected_rls.push( ReferenceLink.new("http://docs.python.org/library/index.html", "under confinement", "3") )
38
+ expected_rls.push( ReferenceLink.new("http://daringfireball.net/markdown", "slaves", "1") )
39
+
40
+ actual_rls = Document.new(@file).reference_links
41
+
42
+ actual_rls.count.should == 4
43
+
44
+ for i in 0..(actual_rls.count-1)
45
+ actual_rls[i].to_s.should == expected_rls[i].to_s
46
+ end
47
+ end
48
+
49
+ it "should convert inline links to reference links and renumber labels in order" do
50
+ actual = Document.new(@inline_file).clean_and_format
51
+ expected = File.open(@clean_file).readlines.join
52
+
53
+ actual.should == expected
54
+ end
55
+
56
+ it "should not remove reference labels that are not used in the text"
57
+
58
+ it "should handle reference links that look [like this]"
59
+
60
+ it "should handle reference links that look [like this][]"
24
61
 
25
- it "should correctly generate a new list of references" do
26
- Poppins::Document.new(@file).ordinal_references.should == ["[1]: http://www.google.com/", "[2]: http://www.kungfugrippe.com/", "[3]: http://docs.python.org/library/index.html", "[4]: http://daringfireball.net/markdown/"]
27
62
  end
28
63
  end
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ describe Poppins::InlineLink do
4
+
5
+ before :each do
6
+ @url = "http://google.com"
7
+ @link_text = "Google"
8
+ end
9
+
10
+ it "should initialize with a url and a link_text" do
11
+ il = Poppins::InlineLink.new(@url, @link_text)
12
+ il.url.should == @url
13
+ il.link_text.should == @link_text
14
+ end
15
+
16
+ it "should correctly produce the in-text version of the link_text" do
17
+ il = Poppins::InlineLink.new(@url, @link_text)
18
+ il.as_found_in_text.should == "[Google](http://google.com)"
19
+ end
20
+
21
+ it "should be able to change the link text" do
22
+ il = Poppins::InlineLink.new(@url, @link_text)
23
+ il.link_text.should == @link_text
24
+ il.link_text = "A Search Engine"
25
+ il.link_text.should == "A Search Engine"
26
+ end
27
+
28
+ it "should have a regex to identify itself" do
29
+ il = Poppins::InlineLink.new(@url, @link_text)
30
+
31
+ sample_text = "This is a [more complex](http://google.com) example."
32
+ good_match = sample_text.match(il.regex)
33
+ good_match.should_not be nil
34
+
35
+ bad_sample_text = "This example [shouldn't work](http://yahoo.com)."
36
+ bad_match = bad_sample_text.match(il.regex)
37
+ bad_match.should be nil
38
+ end
39
+ end
40
+
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe Poppins::ReferenceLink do
4
+
5
+ before :each do
6
+ @link = "http://google.com"
7
+ @label = "Google"
8
+ end
9
+
10
+ it "should initialize with a link and a label" do
11
+ rl = Poppins::ReferenceLink.new(@link, @label)
12
+ rl.url.should == @link
13
+ rl.link_text.should == @label
14
+ end
15
+
16
+ it "should correctly produce the end reference" do
17
+ rl = Poppins::ReferenceLink.new(@link, @label)
18
+ rl.as_end_reference.should == "[Google]: http://google.com"
19
+ end
20
+
21
+ it "should correctly produce the in-text version of the label" do
22
+ rl = Poppins::ReferenceLink.new(@link, @label)
23
+ rl.as_found_in_text.should == "[Google]"
24
+ end
25
+
26
+ end
data/spec/poppins_spec.rb CHANGED
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe Poppins do
4
4
  it "should have a VERSION" do
5
- Poppins::VERSION.should == "0.0.1"
5
+ Poppins::VERSION.should_not be nil
6
6
  end
7
7
  end
8
8
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: poppins
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-03 00:00:00.000000000 Z
12
+ date: 2012-10-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -27,6 +27,22 @@ dependencies:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: guard-rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
30
46
  description: Poppins is a basic formatter for Markdown files.
31
47
  email:
32
48
  - akmassey@gatech.edu
@@ -36,17 +52,28 @@ extensions: []
36
52
  extra_rdoc_files: []
37
53
  files:
38
54
  - .gitignore
55
+ - CHANGES.md
39
56
  - Gemfile
57
+ - Guardfile
40
58
  - LICENSE
41
59
  - README.md
42
60
  - Rakefile
43
61
  - bin/poppins
44
62
  - lib/poppins.rb
45
63
  - lib/poppins/document.rb
64
+ - lib/poppins/inline_link.rb
65
+ - lib/poppins/reference_link.rb
46
66
  - lib/poppins/version.rb
47
67
  - poppins.gemspec
68
+ - spec/data/clean_formatted_sample.md
69
+ - spec/data/implicit_references.md
70
+ - spec/data/inline_choke.md
71
+ - spec/data/mixed.md
48
72
  - spec/data/sample.md
73
+ - spec/data/sample_inline.md
49
74
  - spec/lib/document_spec.rb
75
+ - spec/lib/inline_link_spec.rb
76
+ - spec/lib/reference_link_spec.rb
50
77
  - spec/poppins_spec.rb
51
78
  - spec/spec_helper.rb
52
79
  homepage: ''
@@ -63,7 +90,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
63
90
  version: '0'
64
91
  segments:
65
92
  - 0
66
- hash: 1824278332185590952
93
+ hash: 1115316932625370642
67
94
  required_rubygems_version: !ruby/object:Gem::Requirement
68
95
  none: false
69
96
  requirements:
@@ -72,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
72
99
  version: '0'
73
100
  segments:
74
101
  - 0
75
- hash: 1824278332185590952
102
+ hash: 1115316932625370642
76
103
  requirements: []
77
104
  rubyforge_project:
78
105
  rubygems_version: 1.8.23
@@ -81,7 +108,14 @@ specification_version: 3
81
108
  summary: Poppins formats Markdown files to ensure that reference links are numbered
82
109
  and appear in numerical order.
83
110
  test_files:
111
+ - spec/data/clean_formatted_sample.md
112
+ - spec/data/implicit_references.md
113
+ - spec/data/inline_choke.md
114
+ - spec/data/mixed.md
84
115
  - spec/data/sample.md
116
+ - spec/data/sample_inline.md
85
117
  - spec/lib/document_spec.rb
118
+ - spec/lib/inline_link_spec.rb
119
+ - spec/lib/reference_link_spec.rb
86
120
  - spec/poppins_spec.rb
87
121
  - spec/spec_helper.rb