flannel 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ tmp*
2
+ log*
3
+ *[~#]
4
+ pkg/*
5
+ nbproject*
6
+ coverage*
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Jamal Hansen
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,7 @@
1
+ = flannel
2
+
3
+ A soft comfortable worn in markup language for Ruby.
4
+
5
+ == Copyright
6
+
7
+ Copyright (c) 2009 Jamal Hansen. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,67 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'yaml'
4
+
5
+ begin
6
+ require 'jeweler'
7
+ Jeweler::Tasks.new do |gem|
8
+ gem.name = "flannel"
9
+ gem.summary = %Q{A soft comfortable worn in markup language for Ruby}
10
+ gem.email = "jamal.hansen@gmail.com"
11
+ gem.homepage = "http://github.com/rubyyot/flannel"
12
+ gem.authors = ["Jamal Hansen"]
13
+ gem.rubyforge_project = "flannel"
14
+ gem.add_development_dependency 'technicalpickles-shoulda'
15
+
16
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
17
+ end
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
20
+ end
21
+
22
+ require 'rake/testtask'
23
+ Rake::TestTask.new(:test) do |test|
24
+ test.libs << 'lib' << 'test'
25
+ test.pattern = 'test/**/*_test.rb'
26
+ test.verbose = true
27
+ end
28
+
29
+ begin
30
+ require 'rcov/rcovtask'
31
+ Rcov::RcovTask.new do |test|
32
+ test.libs << 'test'
33
+ test.pattern = 'test/**/*_test.rb'
34
+ test.verbose = true
35
+ end
36
+ rescue LoadError
37
+ task :rcov do
38
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
39
+ end
40
+ end
41
+
42
+ begin
43
+ require 'cucumber/rake/task'
44
+ Cucumber::Rake::Task.new(:features)
45
+ rescue LoadError
46
+ task :features do
47
+ abort "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
48
+ end
49
+ end
50
+
51
+ task :default => :test
52
+
53
+ require 'rake/rdoctask'
54
+ Rake::RDocTask.new do |rdoc|
55
+ if File.exist?('VERSION.yml')
56
+ config = YAML.load(File.read('VERSION.yml'))
57
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
58
+ else
59
+ version = ""
60
+ end
61
+
62
+ rdoc.rdoc_dir = 'rdoc'
63
+ rdoc.title = "flannel #{version}"
64
+ rdoc.rdoc_files.include('README*')
65
+ rdoc.rdoc_files.include('lib/**/*.rb')
66
+ end
67
+
data/VERSION.yml ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ :major: 0
3
+ :minor: 0
4
+ :patch: 1
@@ -0,0 +1,9 @@
1
+ Feature: External link conversion
2
+ In order to create external links
3
+ A user of Flannel
4
+ Will quilt external link markup
5
+
6
+ Scenario: Preformatting text
7
+ Given input of "external_link" text
8
+ When I quilt it with flannel
9
+ Then valid html should be produced
@@ -0,0 +1,3 @@
1
+ Lorem ipsum [dolor sit amet|http://www.example.com], consectetur adipiscing elit. Nam ac magna augue, a pretium magna. Aliquam erat volutpat.
2
+ Proin malesuada, nunc vel [porttitor|www.example.com] [ commodo | http://www.example.com | nunc ], justo. Nam ac magna augue, a pretium magna. Aliquam erat volutpat.
3
+ Proin malesuada, nunc vel [ porttitor | http://www.example.com ] commodo, justo.
@@ -0,0 +1,3 @@
1
+ <p>Lorem ipsum <a href="http://www.example.com" target="_blank">dolor sit amet</a>, consectetur adipiscing elit. Nam ac magna augue, a pretium magna. Aliquam erat volutpat.
2
+ Proin malesuada, nunc vel <a href="http://www.example.com" target="_blank">porttitor</a> <a href="http://www.example.com" title="nunc" target="_blank">commodo</a>, justo. Nam ac magna augue, a pretium magna. Aliquam erat volutpat.
3
+ Proin malesuada, nunc vel <a href="http://www.example.com" target="_blank">porttitor</a> commodo, justo.</p>
@@ -0,0 +1,3 @@
1
+ * Item one
2
+ * Item two
3
+ * This is the much longer item and this item is known simply as item three.
@@ -0,0 +1,3 @@
1
+ <ul><li>Item one</li>
2
+ <li>Item two</li>
3
+ <li>This is the much longer item and this item is known simply as item three.</li></ul>
@@ -0,0 +1,6 @@
1
+
2
+ This is paragraph one.
3
+
4
+ This is paragraph two.
5
+
6
+ This is paragraph three. Watchout for the end of file.
@@ -0,0 +1,5 @@
1
+ <p>This is paragraph one.</p>
2
+
3
+ <p>This is paragraph two.</p>
4
+
5
+ <p>This is paragraph three. Watchout for the end of file.</p>
@@ -0,0 +1,15 @@
1
+ This is a paragraph
2
+
3
+ _ This is preformatted text
4
+ it's cool
5
+
6
+ _ and Spiffy
7
+
8
+ _This is preformatted too
9
+ _
10
+
11
+ _
12
+ So is this
13
+ _
14
+
15
+ This is a paragraph
@@ -0,0 +1,12 @@
1
+ <p>This is a paragraph</p>
2
+
3
+ <pre> This is preformatted text
4
+ it's cool
5
+
6
+ and Spiffy</pre>
7
+
8
+ <pre>This is preformatted too</pre>
9
+
10
+ <pre> So is this</pre>
11
+
12
+ <p>This is a paragraph</p>
@@ -0,0 +1,2 @@
1
+ Lorem ipsum -dolor sit amet>, consectetur adipiscing elit. Nam ac magna augue, a pretium magna. Aliquam erat volutpat.
2
+ Proin malesuada, nunc vel -porttitor> commodo, justo.
@@ -0,0 +1,2 @@
1
+ <p>Lorem ipsum <a href="dolor-sit-amet">dolor sit amet</a>, consectetur adipiscing elit. Nam ac magna augue, a pretium magna. Aliquam erat volutpat.
2
+ Proin malesuada, nunc vel <a href="porttitor">porttitor</a> commodo, justo.</p>
@@ -0,0 +1,2 @@
1
+ <p>Lorem ipsum <a href="http://www.example.com/foo/dolor-sit-amet">dolor sit amet</a>, consectetur adipiscing elit. Nam ac magna augue, a pretium magna. Aliquam erat volutpat.
2
+ Proin malesuada, nunc vel <a href="http://www.example.com/foo/porttitor">porttitor</a> commodo, justo.</p>
@@ -0,0 +1,2 @@
1
+ Lorem ipsum -dolor sit amet>, consectetur adipiscing elit. Nam ac magna augue, a pretium magna. Aliquam erat volutpat.
2
+ Proin malesuada, nunc vel -porttitor> commodo, justo.
@@ -0,0 +1,9 @@
1
+ Feature: Paragraphs
2
+ In order to create lists
3
+ A user of Flannel
4
+ Will quilt list markup
5
+
6
+ Scenario: Wrapping text in paragraphs
7
+ Given input of "paragraph" text
8
+ When I quilt it with flannel
9
+ Then valid html should be produced
@@ -0,0 +1,9 @@
1
+ Feature: List generation
2
+ In order to create lists
3
+ A user of Flannel
4
+ Will quilt list markup
5
+
6
+ Scenario: Creating a list
7
+ Given input of "list" text
8
+ When I quilt it with flannel
9
+ Then valid html should be produced
@@ -0,0 +1,9 @@
1
+ Feature: Preformatted text conversion
2
+ In order to create preformatted text
3
+ A user of Flannel
4
+ Will quilt preformatted text markup
5
+
6
+ Scenario: Preformatting text
7
+ Given input of "preformatted" text
8
+ When I quilt it with flannel
9
+ Then valid html should be produced
@@ -0,0 +1,20 @@
1
+
2
+ Given /^input of "([^\"]*)" text$/ do |feature|
3
+ flannel_filename = File.join("features", "fixtures", "#{feature}.flannel")
4
+ out_filename = File.join("features", "fixtures", "#{feature}.out")
5
+ @before = File.read(flannel_filename)
6
+ @after = File.read(out_filename)
7
+ @wiki_link = nil
8
+ end
9
+
10
+ When /^I quilt it with flannel$/ do
11
+ @output = Flannel.quilt @before, :wiki_link => @wiki_link
12
+ end
13
+
14
+ Then /^valid html should be produced$/ do
15
+ assert_equal @after, @output
16
+ end
17
+
18
+ Given /^a formatter of '([^\"']*)'$/ do |formatter|
19
+ @wiki_link = lambda { |keyword| eval formatter }
20
+ end
@@ -0,0 +1,6 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
2
+ require 'flannel'
3
+
4
+ require 'test/unit/assertions'
5
+
6
+ World(Test::Unit::Assertions)
@@ -0,0 +1,15 @@
1
+ Feature: Paragraphs
2
+ In order to create wiki links
3
+ A user of Flannel
4
+ Will use wiki links
5
+
6
+ Scenario: Creating wiki links
7
+ Given input of "wiki_links" text
8
+ When I quilt it with flannel
9
+ Then valid html should be produced
10
+
11
+ Scenario: Creating wiki links with a custom url
12
+ Given input of "wiki_links" text
13
+ And a formatter of 'http://www.example.com/foo/#{keyword}'
14
+ When I quilt it with flannel
15
+ Then valid html should be produced
data/flannel.gemspec ADDED
@@ -0,0 +1,86 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{flannel}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Jamal Hansen"]
12
+ s.date = %q{2009-12-26}
13
+ s.email = %q{jamal.hansen@gmail.com}
14
+ s.extra_rdoc_files = [
15
+ "LICENSE",
16
+ "README.rdoc"
17
+ ]
18
+ s.files = [
19
+ ".document",
20
+ ".gitignore",
21
+ "LICENSE",
22
+ "README.rdoc",
23
+ "Rakefile",
24
+ "VERSION.yml",
25
+ "features/external_link.feature",
26
+ "features/fixtures/external_link.flannel",
27
+ "features/fixtures/external_link.out",
28
+ "features/fixtures/list.flannel",
29
+ "features/fixtures/list.out",
30
+ "features/fixtures/paragraph.flannel",
31
+ "features/fixtures/paragraph.out",
32
+ "features/fixtures/preformatted.flannel",
33
+ "features/fixtures/preformatted.out",
34
+ "features/fixtures/wiki_links.flannel",
35
+ "features/fixtures/wiki_links.out",
36
+ "features/fixtures/wiki_links_for_lambda.out",
37
+ "features/fixtures/wiki_links_for_lamdba.flannel",
38
+ "features/list.feature",
39
+ "features/paragraph.feature",
40
+ "features/preformatted_text.feature",
41
+ "features/step_definitions/flannel_steps.rb",
42
+ "features/support/env.rb",
43
+ "features/wiki_links.feature",
44
+ "flannel.gemspec",
45
+ "lib/cutting_board.rb",
46
+ "lib/flannel.rb",
47
+ "lib/shears.rb",
48
+ "lib/square.rb",
49
+ "lib/stripe.rb",
50
+ "lib/wrappable.rb",
51
+ "test/cutting_board_test.rb",
52
+ "test/flannel_test.rb",
53
+ "test/shears_test.rb",
54
+ "test/square_test.rb",
55
+ "test/stripe_test.rb",
56
+ "test/test_helper.rb"
57
+ ]
58
+ s.homepage = %q{http://github.com/rubyyot/flannel}
59
+ s.rdoc_options = ["--charset=UTF-8"]
60
+ s.require_paths = ["lib"]
61
+ s.rubyforge_project = %q{flannel}
62
+ s.rubygems_version = %q{1.3.5}
63
+ s.summary = %q{A soft comfortable worn in markup language for Ruby}
64
+ s.test_files = [
65
+ "test/test_helper.rb",
66
+ "test/stripe_test.rb",
67
+ "test/cutting_board_test.rb",
68
+ "test/flannel_test.rb",
69
+ "test/square_test.rb",
70
+ "test/shears_test.rb"
71
+ ]
72
+
73
+ if s.respond_to? :specification_version then
74
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
75
+ s.specification_version = 3
76
+
77
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
78
+ s.add_development_dependency(%q<technicalpickles-shoulda>, [">= 0"])
79
+ else
80
+ s.add_dependency(%q<technicalpickles-shoulda>, [">= 0"])
81
+ end
82
+ else
83
+ s.add_dependency(%q<technicalpickles-shoulda>, [">= 0"])
84
+ end
85
+ end
86
+
@@ -0,0 +1,16 @@
1
+ require 'shears'
2
+
3
+
4
+ module Flannel
5
+ class CuttingBoard
6
+ def initialize params={}
7
+ @wiki_link= params[:wiki_link]
8
+ end
9
+
10
+ def cut markup
11
+ shears = Flannel::Shears.new
12
+ squares = shears.cut markup
13
+ squares.map { |square| square.to_h }.join("\n\n")
14
+ end
15
+ end
16
+ end
data/lib/flannel.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'cutting_board'
2
+
3
+ module Flannel
4
+ def self.quilt markup, params={}
5
+ return nil unless markup
6
+ shears = Flannel::CuttingBoard.new params
7
+ shears.cut markup
8
+ end
9
+ end
data/lib/shears.rb ADDED
@@ -0,0 +1,83 @@
1
+ require 'square'
2
+ require 'stripe'
3
+
4
+ module Flannel
5
+ class Shears
6
+ def cut markup
7
+ @squares = []
8
+ @square = Flannel::Square.new
9
+ @end_preformat = false
10
+
11
+ markup.split("\n").each { |line| cut_into_squares line }
12
+
13
+ @squares << @square
14
+ end
15
+
16
+ def cut_into_squares line
17
+ if need_new_square? line
18
+ shift_square
19
+ else
20
+ add line
21
+ end
22
+ end
23
+
24
+ def shift_square
25
+ @squares << @square unless @square.blank?
26
+ @square = Flannel::Square.new
27
+ end
28
+
29
+ def need_new_square? line
30
+ @square.style == :preformatted ? @end_preformat : empty?(line.strip)
31
+ end
32
+
33
+ def add line
34
+ @preformatted_marker_line = false
35
+ line = strip_markers line
36
+ line = remove_hanging_preformatted_lines line
37
+
38
+ @square << line unless line.nil?
39
+ end
40
+
41
+ def remove_hanging_preformatted_lines line
42
+ if @preformatted_marker_line
43
+ @end_preformat = @square.populated?
44
+ if line.strip == ""
45
+ return nil
46
+ end
47
+ else
48
+ @end_preformat = false
49
+ end
50
+ line
51
+ end
52
+
53
+ def strip_markers line
54
+ parts = line.match(/^([=_*]+)(.*)/)
55
+
56
+ if parts
57
+ set_style parts[1]
58
+ line = parts[2]
59
+ end
60
+ line
61
+ end
62
+
63
+ def set_style marker
64
+ if marker
65
+ case marker[0]
66
+ when 61 # equals (header)
67
+ style = "header_#{marker.length}"
68
+ @square.style = style.to_sym
69
+ when 95 # underscore (preformatted)
70
+ @square.style = :preformatted
71
+ @preformatted_marker_line = true
72
+ when 42 # star (list)
73
+ @square.style = :list
74
+ end
75
+ end
76
+ end
77
+
78
+ def empty? str
79
+ str.nil? || str == ""
80
+ end
81
+ end
82
+ end
83
+
data/lib/square.rb ADDED
@@ -0,0 +1,90 @@
1
+ require 'wrappable'
2
+
3
+ module Flannel
4
+ class Square
5
+ include Flannel::Wrappable
6
+ attr_accessor :style
7
+
8
+ def initialize params={}
9
+ @tags ={:preformatted => "pre", :list => "ul", :header_1 => "h1", :header_2 => "h2", :header_3 => "h3", :header_4 => "h4", :header_5 => "h5", :header_6 => "h6"}
10
+ @stripes = []
11
+ @style = :paragraph
12
+ end
13
+
14
+ def << text
15
+ text = text.strip unless @style == :preformatted
16
+ @stripes << Flannel::Stripe.stitch(text, :style=>@style)
17
+ end
18
+
19
+ def to_s
20
+ @stripes.map { |stripe| stripe.weave }.join("\n")
21
+ end
22
+
23
+ def blank?
24
+ (@stripes.length == 0 || all_stripes_blank)
25
+ end
26
+
27
+ def populated?
28
+ !blank?
29
+ end
30
+
31
+ def all_stripes_blank
32
+ @stripes.each do |stripe|
33
+ return false if !stripe.empty?
34
+ end
35
+
36
+ return true
37
+ end
38
+
39
+ def to_h
40
+ @post_wrap = nil
41
+ lines = @stripes.map { |stripe| stripe.to_h }
42
+
43
+ quilt lines
44
+ end
45
+
46
+ def quilt lines
47
+ output = lines.join("\n")
48
+ output = convert_external_links output
49
+ return wrap(output, find_tag)
50
+ end
51
+
52
+ def preformatted
53
+ @style == :preformatted
54
+ end
55
+
56
+ def convert_external_links text
57
+ return text if preformatted
58
+ text.gsub(/\[([^\|]*\|[^\]]*)\]/) { |match| build_external_link match }
59
+ end
60
+
61
+ def build_external_link match
62
+ text, url, title = match[1..-2].split("|", 3)
63
+
64
+ url = format_link url.strip
65
+ text.strip!
66
+ title.strip! if title
67
+
68
+ if title
69
+ %{<a href="#{url}" title="#{title}" target="_blank">#{text}</a>}
70
+ else
71
+ %{<a href="#{url}" target="_blank">#{text}</a>}
72
+ end
73
+ end
74
+
75
+ def format_link url
76
+ return url if /:\/\// =~ url
77
+ "http://#{url}"
78
+ end
79
+
80
+ def find_tag
81
+ if @style && @tags.has_key?(@style)
82
+ tag = @tags[@style]
83
+ else
84
+ tag = "p"
85
+ end
86
+ tag
87
+ end
88
+ end
89
+ end
90
+
data/lib/stripe.rb ADDED
@@ -0,0 +1,67 @@
1
+ require 'wrappable'
2
+
3
+ module Flannel
4
+ class Stripe
5
+ include Wrappable
6
+ attr_reader :weave
7
+
8
+ def self.stitch weave="", params={}
9
+ Flannel::Stripe.new weave, params
10
+ end
11
+
12
+ def initialize weave="", params={}
13
+ @weave = weave
14
+ @wiki_link = params[:wiki_link]
15
+ @style = params[:style]
16
+ end
17
+
18
+ def wiki_link topic
19
+ if @wiki_link
20
+ @wiki_link.call(permalink topic)
21
+ else
22
+ permalink topic[1..-2]
23
+ end
24
+ end
25
+
26
+ def permalink topic
27
+ require 'iconv'
28
+ # thanks to ismasan http://snippets.dzone.com/posts/show/4457
29
+ (Iconv.new('US-ASCII//TRANSLIT', 'utf-8').iconv topic).gsub(/[^\w\s\-]/,'').gsub(/[^\w]|[\_]/,' ').split.join('-').downcase
30
+ end
31
+
32
+ def empty?
33
+ @weave == nil || @weave.strip == ""
34
+ end
35
+
36
+ def build_wiki_links
37
+ return @weave if preformatted
38
+ @weave.gsub(/-\w(.*)\w>/) { |match| %{<a href="#{wiki_link match}">#{match[1..-2]}</a>}}
39
+ end
40
+
41
+ def to_h
42
+ text = build_wiki_links
43
+ markup text
44
+ end
45
+
46
+ def preformatted
47
+ @style == :preformatted
48
+ end
49
+
50
+ def list
51
+ @style == :list
52
+ end
53
+
54
+ def markup text
55
+ return html_escape text if preformatted
56
+
57
+ tag = "li" if list
58
+ wrap(text, tag)
59
+ end
60
+
61
+ def html_escape text
62
+ require 'cgi'
63
+
64
+ CGI::escapeHTML(text)
65
+ end
66
+ end
67
+ end
data/lib/wrappable.rb ADDED
@@ -0,0 +1,17 @@
1
+ module Flannel
2
+ module Wrappable
3
+ def wrap content, tag
4
+ if empty_string?(content) || empty_string?(tag)
5
+ return content
6
+ end
7
+
8
+ content.strip! unless tag == "pre"
9
+
10
+ "<#{tag}>#{content}</#{tag}>"
11
+ end
12
+
13
+ def empty_string? str
14
+ str.nil? || str.strip == ""
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,54 @@
1
+ require 'test_helper'
2
+
3
+ class CuttingBoardTest < Test::Unit::TestCase
4
+ context "basic behavior" do
5
+ setup do
6
+ @board = Flannel::CuttingBoard.new
7
+ end
8
+
9
+ should "strip and convert underscores to pre tags" do
10
+ markup = "_foo\n\n bar\n_"
11
+ assert_equal "<pre>foo\n\n bar</pre>", @board.cut(markup)
12
+ end
13
+
14
+ should "preformat text when both start and end line have the markers" do
15
+ markup = "_foo\n\n_ bar"
16
+ assert_equal "<pre>foo\n\n bar</pre>", @board.cut(markup)
17
+ end
18
+
19
+ should "not replace in preformatted text" do
20
+ markup = "_4 - 2 > 2 - 2\n_"
21
+ assert_equal '<pre>4 - 2 &gt; 2 - 2</pre>', @board.cut(markup)
22
+ end
23
+ end
24
+
25
+ context "When block starts with one or more equals signs, it" do
26
+ setup do
27
+ @board = Flannel::CuttingBoard.new
28
+ end
29
+
30
+ should "convert one equals to a header one" do
31
+ markup = "= Some header"
32
+ result = "<h1>Some header</h1>"
33
+
34
+ assert_equal result, @board.cut(markup)
35
+ end
36
+
37
+ should "convert two equals to a header two" do
38
+ markup = "== Some header"
39
+ result = "<h2>Some header</h2>"
40
+
41
+ assert_equal result, @board.cut(markup)
42
+ end
43
+ end
44
+
45
+ context "When block starts with a star, it" do
46
+ should "tell square that it's a list, so that it will be wrapped in ul tags" do
47
+ board = Flannel::CuttingBoard.new
48
+ markup = "* Yadda"
49
+ result = "<ul><li>Yadda</li></ul>"
50
+
51
+ assert_equal result, board.cut(markup)
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,12 @@
1
+ require 'test_helper'
2
+
3
+ class FlannelTest < Test::Unit::TestCase
4
+ should "wrap functionality up in a neat package" do
5
+ markup = "== Foo\n\n* Bar"
6
+ assert_equal "<h2>Foo</h2>\n\n<ul><li>Bar</li></ul>", Flannel.quilt(markup)
7
+ end
8
+
9
+ should "return nil if text is nil" do
10
+ assert_nil Flannel.quilt(nil)
11
+ end
12
+ end
@@ -0,0 +1,43 @@
1
+ require 'test_helper'
2
+
3
+ class ShearsTest < Test::Unit::TestCase
4
+ context "basic behavior" do
5
+ setup do
6
+ @shears = Flannel::Shears.new
7
+ end
8
+
9
+ should "split a flannel document into squares based on blank lines" do
10
+ markup = "foo\n\nbar"
11
+
12
+ squares = @shears.cut markup
13
+ assert_equal 2, squares.length
14
+ assert_equal "foo", squares[0].to_s
15
+ assert_equal "bar", squares[1].to_s
16
+ end
17
+
18
+ should "not split preformatted text based on blank lines" do
19
+ markup = "_foo\n\nbar\n_"
20
+
21
+ squares = @shears.cut markup
22
+ assert_equal 1, squares.length
23
+ assert_equal :preformatted, squares[0].style
24
+ end
25
+
26
+
27
+ should "separate preformatted blocks" do
28
+ markup = "_foo\n_\n\n_bar\n_"
29
+
30
+ squares = @shears.cut markup
31
+ assert_equal 2, squares.length
32
+ assert_equal :preformatted, squares[0].style
33
+ assert_equal :preformatted, squares[1].style
34
+ end
35
+
36
+ should "strip preformatted markers when found" do
37
+ markup = "_foo\n\nbar\n_"
38
+
39
+ squares = @shears.cut markup
40
+ assert_equal "foo\n\nbar", squares[0].to_s
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,103 @@
1
+ require 'test_helper'
2
+ require 'stripe'
3
+
4
+ class SquareTest < Test::Unit::TestCase
5
+ context "basic behavior" do
6
+ setup do
7
+ @square = Flannel::Square.new
8
+ end
9
+
10
+ should "accept strings with <<" do
11
+ @square << "foo"
12
+ assert_equal "foo", @square.to_s
13
+ end
14
+
15
+ should "be blank when there are no stripes" do
16
+ assert @square.blank?
17
+ @square << "foo"
18
+ assert !@square.blank?
19
+ end
20
+
21
+ should "be blank when the first stripe is an empty string" do
22
+ @square << ""
23
+ assert @square.blank?
24
+ end
25
+
26
+ should "be blank when the first stripe is whitespace" do
27
+ @square << " "
28
+ assert @square.blank?
29
+ end
30
+
31
+ should "be blank when the all stripes are empty strings" do
32
+ @square << ""
33
+ @square << ""
34
+ @square << ""
35
+ assert @square.blank?
36
+ end
37
+
38
+ should "be blank when the all stripes are whitespace" do
39
+ @square << " "
40
+ @square << " "
41
+ @square << ""
42
+ assert @square.blank?
43
+ end
44
+
45
+ should "not be blank when a stripe is not blank" do
46
+ @square << " "
47
+ @square << " "
48
+ @square << "foo"
49
+ assert !@square.blank?
50
+ end
51
+
52
+ should "return html" do
53
+ @square << "foo"
54
+ assert_equal "<p>foo</p>", @square.to_h
55
+ end
56
+
57
+ should "accept a style" do
58
+ @square.style = :preformatted
59
+ assert_equal :preformatted, @square.style
60
+ end
61
+ end
62
+
63
+ context "style" do
64
+ should "accept an optional style parameter" do
65
+ square = Flannel::Square.new
66
+ square.style = :foo
67
+ end
68
+
69
+ should "wrap in pre tags when preformatted" do
70
+ square = Flannel::Square.new
71
+ square.style = :preformatted
72
+ square << "foo"
73
+ assert_equal "<pre>foo</pre>", square.to_h
74
+ end
75
+
76
+ should "wrap in ul tags when unordered_list" do
77
+ square = Flannel::Square.new
78
+ square.style = :list
79
+ square << "foo"
80
+ assert_equal "<ul><li>foo</li></ul>", square.to_h
81
+ end
82
+ end
83
+
84
+ context "external links" do
85
+ should "convert [|] pattern to an external link" do
86
+ square = Flannel::Square.new
87
+ square << "yadda [yadda|http://example.com] yadda"
88
+ assert_equal '<p>yadda <a href="http://example.com" target="_blank">yadda</a> yadda</p>', square.to_h
89
+ end
90
+
91
+ should "add http:// to external links" do
92
+ square = Flannel::Square.new
93
+ square << "yadda [yadda|example.com] yadda"
94
+ assert_equal '<p>yadda <a href="http://example.com" target="_blank">yadda</a> yadda</p>', square.to_h
95
+ end
96
+
97
+ should "add create title if provided to external links" do
98
+ square = Flannel::Square.new
99
+ square << "yadda [yadda|example.com|My title] yadda"
100
+ assert_equal '<p>yadda <a href="http://example.com" title="My title" target="_blank">yadda</a> yadda</p>', square.to_h
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,102 @@
1
+ require 'test_helper'
2
+ require 'stripe'
3
+
4
+ class StripeTest < Test::Unit::TestCase
5
+ context "basic operations" do
6
+ setup do
7
+ @stripe = Flannel::Stripe.stitch "foo"
8
+ end
9
+
10
+ should "be of of kind Flannel::Stripe" do
11
+ assert Flannel::Stripe, @stripe.class
12
+ end
13
+
14
+ should "create instance with stitch" do
15
+ assert_equal "foo", @stripe.weave
16
+ end
17
+
18
+ should "return html fragment with to_h" do
19
+ assert_equal "foo", @stripe.to_h
20
+ end
21
+ end
22
+
23
+ context "building wiki links" do
24
+ setup do
25
+ wiki_link = lambda { |keyword| "http://www.example.com/foo/#{keyword}"}
26
+ @stripe = Flannel::Stripe.stitch "the -roof is on fire>", :wiki_link => wiki_link
27
+ end
28
+
29
+ should "build wiki links based on a lambda" do
30
+ assert_equal "http://www.example.com/foo/cheese", @stripe.wiki_link("cheese")
31
+ end
32
+
33
+ should "find and replace wiki link markup" do
34
+ assert_equal 'the <a href="http://www.example.com/foo/roof-is-on-fire">roof is on fire</a>', @stripe.to_h
35
+ end
36
+
37
+ should "permalink topics when making wiki links" do
38
+ assert_equal "http://www.example.com/foo/cheese-tastes-good", @stripe.wiki_link("cheese tastes good")
39
+ end
40
+ end
41
+
42
+ context "no lambda is provided" do
43
+ setup do
44
+ @stripe = Flannel::Stripe.stitch "baz"
45
+ end
46
+
47
+ should "output the wiki text" do
48
+ assert_equal "cheese", @stripe.wiki_link("-cheese>")
49
+ end
50
+
51
+ should "prermalink the wiki text" do
52
+ assert_equal "cheese-is-good", @stripe.wiki_link("-cheese is good>")
53
+ end
54
+ end
55
+
56
+ context "replacing wiki links" do
57
+ should "replace surrounded by - and > with a wiki link" do
58
+ stripe = Flannel::Stripe.stitch("red, -green>, refactor")
59
+ assert_equal 'red, <a href="green">green</a>, refactor', stripe.to_h
60
+ end
61
+
62
+ should "not replace surrounded by - and > with a wiki link if spaced" do
63
+ stripe = Flannel::Stripe.stitch("red, - green >, refactor")
64
+ assert_equal 'red, - green >, refactor', stripe.to_h
65
+ end
66
+
67
+ should "not replace surrounded by - and > with a wiki link if spaced on right" do
68
+ stripe = Flannel::Stripe.stitch("red, -green >, refactor")
69
+ assert_equal 'red, -green >, refactor', stripe.to_h
70
+ end
71
+
72
+ should "not replace surrounded by - and > with a wiki link if spaced on left" do
73
+ stripe = Flannel::Stripe.stitch("red, - green>, refactor")
74
+ assert_equal 'red, - green>, refactor', stripe.to_h
75
+ end
76
+ end
77
+
78
+ context "preformatted text" do
79
+ should "html escape preformatted text" do
80
+ stripe = Flannel::Stripe.stitch "<p>& foo</p>", :style => :preformatted
81
+ assert_equal "&lt;p&gt;&amp; foo&lt;/p&gt;", stripe.to_h
82
+ end
83
+ end
84
+
85
+ context "making permalinks" do
86
+ setup do
87
+ @stripe = Flannel::Stripe.stitch ""
88
+ end
89
+
90
+ should "replace spaces with dashes" do
91
+ assert_equal "get-the-box", @stripe.permalink("get the box")
92
+ end
93
+
94
+ should "replace multiple spaces with single dashes" do
95
+ assert_equal "get-the-box", @stripe.permalink("get the box")
96
+ end
97
+
98
+ should "replace odd characters with dashes" do
99
+ assert_equal "get-the-box", @stripe.permalink("get the @#)(* box")
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'flannel'
8
+
9
+ class Test::Unit::TestCase
10
+ end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: flannel
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jamal Hansen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-12-26 00:00:00 -06:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: technicalpickles-shoulda
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description:
26
+ email: jamal.hansen@gmail.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README.rdoc
34
+ files:
35
+ - .document
36
+ - .gitignore
37
+ - LICENSE
38
+ - README.rdoc
39
+ - Rakefile
40
+ - VERSION.yml
41
+ - features/external_link.feature
42
+ - features/fixtures/external_link.flannel
43
+ - features/fixtures/external_link.out
44
+ - features/fixtures/list.flannel
45
+ - features/fixtures/list.out
46
+ - features/fixtures/paragraph.flannel
47
+ - features/fixtures/paragraph.out
48
+ - features/fixtures/preformatted.flannel
49
+ - features/fixtures/preformatted.out
50
+ - features/fixtures/wiki_links.flannel
51
+ - features/fixtures/wiki_links.out
52
+ - features/fixtures/wiki_links_for_lambda.out
53
+ - features/fixtures/wiki_links_for_lamdba.flannel
54
+ - features/list.feature
55
+ - features/paragraph.feature
56
+ - features/preformatted_text.feature
57
+ - features/step_definitions/flannel_steps.rb
58
+ - features/support/env.rb
59
+ - features/wiki_links.feature
60
+ - flannel.gemspec
61
+ - lib/cutting_board.rb
62
+ - lib/flannel.rb
63
+ - lib/shears.rb
64
+ - lib/square.rb
65
+ - lib/stripe.rb
66
+ - lib/wrappable.rb
67
+ - test/cutting_board_test.rb
68
+ - test/flannel_test.rb
69
+ - test/shears_test.rb
70
+ - test/square_test.rb
71
+ - test/stripe_test.rb
72
+ - test/test_helper.rb
73
+ has_rdoc: true
74
+ homepage: http://github.com/rubyyot/flannel
75
+ licenses: []
76
+
77
+ post_install_message:
78
+ rdoc_options:
79
+ - --charset=UTF-8
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: "0"
87
+ version:
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: "0"
93
+ version:
94
+ requirements: []
95
+
96
+ rubyforge_project: flannel
97
+ rubygems_version: 1.3.5
98
+ signing_key:
99
+ specification_version: 3
100
+ summary: A soft comfortable worn in markup language for Ruby
101
+ test_files:
102
+ - test/test_helper.rb
103
+ - test/stripe_test.rb
104
+ - test/cutting_board_test.rb
105
+ - test/flannel_test.rb
106
+ - test/square_test.rb
107
+ - test/shears_test.rb