MiniMarkup 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,6 @@
1
+ === 1.0.0 / 2008-12-17
2
+
3
+ * 1 major enhancement
4
+
5
+ * Birthday!
6
+
@@ -0,0 +1,6 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ lib/mini_markup.rb
6
+ test/test_mini_markup.rb
@@ -0,0 +1,49 @@
1
+ = MiniMarkup
2
+
3
+ * http://rubyforge.org/projects/uwruby
4
+ * http://uwruby.rubyforge.org/mini_markup/
5
+
6
+ == DESCRIPTION:
7
+
8
+ This is a simplified version of how Textile works
9
+
10
+ == FEATURES/PROBLEMS:
11
+
12
+ Currently includes replacement <b> <i> and <p>
13
+
14
+ == SYNOPSIS:
15
+
16
+ Coming soon
17
+
18
+ == REQUIREMENTS:
19
+
20
+ * None
21
+
22
+ == INSTALL:
23
+
24
+ * sudo gem install minimarkup
25
+
26
+ == LICENSE:
27
+
28
+ (The MIT License)
29
+
30
+ Copyright (c) 2008 FIX
31
+
32
+ Permission is hereby granted, free of charge, to any person obtaining
33
+ a copy of this software and associated documentation files (the
34
+ 'Software'), to deal in the Software without restriction, including
35
+ without limitation the rights to use, copy, modify, merge, publish,
36
+ distribute, sublicense, and/or sell copies of the Software, and to
37
+ permit persons to whom the Software is furnished to do so, subject to
38
+ the following conditions:
39
+
40
+ The above copyright notice and this permission notice shall be
41
+ included in all copies or substantial portions of the Software.
42
+
43
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
44
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
45
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
46
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
47
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
48
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
49
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,12 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+ require './lib/mini_markup.rb'
6
+
7
+ Hoe.new('MiniMarkup', MiniMarkup::VERSION) do |p|
8
+ p.rubyforge_name = 'uwruby'
9
+ p.developer('Jordan Dobson', 'jordandobson@gmail.com')
10
+ end
11
+
12
+ # vim: syntax=Ruby
@@ -0,0 +1,22 @@
1
+ class MiniMarkup
2
+ VERSION = '1.0.0'
3
+ B = {:seek => /(\*\b)([a-zA-Z0-9 -]+)(\b\*)/, :tag => "b"}
4
+ I = {:seek => /(_(?=\S))([a-zA-Z0-9 -&]+)((?=\S)_)/, :tag => "i"}
5
+ P = {:seek => /()((.+(\n|\z)){1,})/, :tag => "p"}
6
+
7
+ attr_accessor :txt
8
+
9
+ def initialize (t="")
10
+ t = t.to_s if !t.is_a?(String)
11
+ @txt = t
12
+ end
13
+
14
+ def raw_to_tags (m=nil)
15
+ @txt.gsub(m[:seek]) { "<#{m[:tag]}>#{$2.chomp}</#{m[:tag]}>" }
16
+ end
17
+
18
+ def add_b_tags; raw_to_tags B; end;
19
+ def add_i_tags; raw_to_tags I; end;
20
+ def add_p_tags; raw_to_tags P; end;
21
+
22
+ end
@@ -0,0 +1,173 @@
1
+ #!/usr/bin/env ruby -w
2
+
3
+ require 'test/unit'
4
+ require 'mini_markup.rb'
5
+
6
+ ##
7
+ # Student Name: Jordan Dobson
8
+ # Homework Week: 8
9
+ #
10
+
11
+ class TestMiniMarkup < Test::Unit::TestCase
12
+
13
+ def setup
14
+
15
+ @inst = MiniMarkup.new
16
+
17
+ @no_inline_change = "* This text_should be unchanged."
18
+
19
+ @b_simple_before = "*bold text* *b*"
20
+ @b_simple_after = "<b>bold text</b> <b>b</b>"
21
+
22
+ @b_complex_before = "* this shouldn't b*e bold* \n ** but this should be *bold text*"
23
+ @b_complex_after = "* this shouldn't b<b>e bold</b> \n ** but this should be <b>bold text</b>"
24
+
25
+ @i_simple_before = "_italics_ _i_"
26
+ @i_simple_after = "<i>italics</i> <i>i</i>"
27
+
28
+ @i_complex_before = "http://_squadblog_.com/news_view/ th_is i_s _awesome_ and really _ _should work_\n _here_ "
29
+ @i_complex_after = "http://<i>squadblog</i>.com/news_view/ th<i>is i</i>s <i>awesome</i> and really _ <i>should work</i>\n <i>here</i> "
30
+
31
+ @p_simple_before = "We release about *50 new accounts weekly* on Glue, our simple web & mobile content publishing tool"
32
+ @p_simple_after = "<p>We release about *50 new accounts weekly* on Glue, our simple web & mobile content publishing tool</p>"
33
+
34
+ @p_medium_before = "We release about *50 new accounts weekly* on Glue, our simple web & mobile content publishing tool\n\nHere's some topics to help you get started!"
35
+ @p_medium_after = "<p>We release about *50 new accounts weekly* on Glue, our simple web & mobile content publishing tool</p>\n<p>Here's some topics to help you get started!</p>"
36
+
37
+ @p_complex_before = "We release about *50 new accounts weekly* on Glue, our simple web & mobile content publishing tool\n\nHere's some topics to help you get started!\n\n\n\n*Glue Help Blog Topics*"
38
+ @p_complex_after = "<p>We release about *50 new accounts weekly* on Glue, our simple web & mobile content publishing tool</p>\n<p>Here's some topics to help you get started!</p>\n\n\n<p>*Glue Help Blog Topics*</p>"
39
+
40
+ @p_with_breaks_before = "We release about *50 new accounts weekly* on Glue,\n our simple web & mobile content publishing tool\n\nHere's some topics to help you get started!\n\n*Glue Help Blog Topics*"
41
+ @p_with_breaks_after = "<p>We release about *50 new accounts weekly* on Glue,\n our simple web & mobile content publishing tool</p>\n<p>Here's some topics to help you get started!</p>\n<p>*Glue Help Blog Topics*</p>"
42
+
43
+ @all_with_breaks_before = "We release about *50 new accounts weekly* on Glue,\n our simple _web & mobile_ _content publish_ing tool\n\nHere's some topics to help you get started!\n\n*Glue Help Blog Topics*"
44
+
45
+
46
+ @all_with_breaks_after = "<p>We release about <b>50 new accounts weekly</b> on Glue,\n our simple <i>web & mobile</i> <i>content publish</i>ing tool</p>\n\n<p>Here's some topics to help you get started!</p>\n\n<p><b>Glue Help Blog Topics</b></p>"
47
+
48
+ end
49
+
50
+ ###
51
+ # Setup
52
+ #
53
+ # Test our setup file is good
54
+ def test_is_mini_markup
55
+ assert_kind_of MiniMarkup, @inst
56
+ end
57
+
58
+ ###
59
+ # DataType
60
+ #
61
+ # Make sure it returns a string if given something different
62
+ def test_always_string_on_init
63
+ assert_kind_of String, MiniMarkup.new([42,"bad",[]]).txt
64
+ assert_kind_of String, MiniMarkup.new({:bad => "bad"}).txt
65
+ assert_kind_of String, MiniMarkup.new(42).txt
66
+ end
67
+
68
+ ###
69
+ # Empty
70
+ #
71
+ # Ensure if nothing sent it returns nil
72
+ def test_for_nil_if_no_params
73
+ assert_equal "", @inst.txt
74
+ end
75
+
76
+ # Ensure if tags added on nil still returns
77
+ def test_return_if_empty
78
+ assert_equal "", @inst.add_b_tags
79
+ assert_equal "", @inst.add_i_tags
80
+ assert_equal "", @inst.add_p_tags
81
+ end
82
+
83
+ ###
84
+ # Initialize
85
+ #
86
+ # Ensure Data returns unchanged after initialize
87
+ def test_no_replacements
88
+ actual = @no_inline_change
89
+ obj = MiniMarkup.new(actual)
90
+ expected = obj.txt
91
+ assert_equal expected, actual
92
+ end
93
+
94
+ ###
95
+ # Bold
96
+ #
97
+ # Check that no bold matches are returned
98
+ def test_no_bold_matches
99
+ actual = MiniMarkup.new(@no_inline_change).add_b_tags
100
+ expected = @no_inline_change
101
+ assert_equal expected, actual
102
+ end
103
+
104
+ # Check for simple bold matches
105
+ def test_find_bold_simple_matches
106
+ actual = MiniMarkup.new(@b_simple_before).add_b_tags
107
+ expected = @b_simple_after
108
+ assert_equal expected, actual
109
+ end
110
+
111
+ # Check for complex bold matches
112
+ def test_find_bold_complex_matches
113
+ actual = MiniMarkup.new(@b_complex_before).add_b_tags
114
+ expected = @b_complex_after
115
+ assert_equal expected, actual
116
+ end
117
+
118
+ ###
119
+ # Italic
120
+ #
121
+ # Check that no italic matches are returned
122
+ def test_no_italic_matches
123
+ actual = MiniMarkup.new(@no_inline_change).add_i_tags
124
+ expected = @no_inline_change
125
+ assert_equal expected, actual
126
+ end
127
+
128
+ # Check for simple italic matches
129
+ def test_find_italic_simple_matches
130
+ actual = MiniMarkup.new(@i_simple_before).add_i_tags
131
+ expected = @i_simple_after
132
+ assert_equal expected, actual
133
+ end
134
+
135
+ # Check for complex italic matches
136
+ def test_find_italic_complex_matches
137
+ actual = MiniMarkup.new(@i_complex_before).add_i_tags
138
+ expected = @i_complex_after
139
+ assert_equal expected, actual
140
+ end
141
+
142
+ ###
143
+ # Paragraph
144
+ #
145
+ # Check that simple paragraph matches are returned
146
+ def test_find_paragraph_simple
147
+ actual = MiniMarkup.new(@p_simple_before).add_p_tags
148
+ expected = @p_simple_after
149
+ assert_equal expected, actual
150
+ end
151
+
152
+ # Check that well formed paragraph matches are returned
153
+ def test_find_paragraph_medium
154
+ actual = MiniMarkup.new(@p_medium_before).add_p_tags
155
+ expected = @p_medium_after
156
+ assert_equal expected, actual
157
+ end
158
+
159
+ # Check that poorly formed paragraph matches are returned
160
+ def test_find_paragraph_complex
161
+ actual = MiniMarkup.new(@p_complex_before).add_p_tags
162
+ expected = @p_complex_after
163
+ assert_equal expected, actual
164
+ end
165
+
166
+ # Check that line breaks are preserved inside paragraphs
167
+ def test_find_paragraph_keep breaks
168
+ actual = MiniMarkup.new(@p_with_breaks_before).add_p_tags
169
+ expected = @p_with_breaks_after
170
+ assert_equal expected, actual
171
+ end
172
+
173
+ end
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: MiniMarkup
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jordan Dobson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-12-17 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hoe
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.8.2
24
+ version:
25
+ description: This is a simplified version of how Textile works
26
+ email:
27
+ - jordandobson@gmail.com
28
+ executables: []
29
+
30
+ extensions: []
31
+
32
+ extra_rdoc_files:
33
+ - History.txt
34
+ - Manifest.txt
35
+ - README.txt
36
+ files:
37
+ - History.txt
38
+ - Manifest.txt
39
+ - README.txt
40
+ - Rakefile
41
+ - lib/mini_markup.rb
42
+ - test/test_mini_markup.rb
43
+ has_rdoc: true
44
+ homepage: http://rubyforge.org/projects/uwruby
45
+ post_install_message:
46
+ rdoc_options:
47
+ - --main
48
+ - README.txt
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ version:
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ version:
63
+ requirements: []
64
+
65
+ rubyforge_project: uwruby
66
+ rubygems_version: 1.3.1
67
+ signing_key:
68
+ specification_version: 2
69
+ summary: This is a simplified version of how Textile works
70
+ test_files:
71
+ - test/test_mini_markup.rb