pink_shirt 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/changelog ADDED
@@ -0,0 +1,4 @@
1
+ 0.0.2
2
+ whitespace and documentation formatting
3
+ 0.0.1
4
+ intial release
@@ -1,33 +1,34 @@
1
1
  class PinkShirt
2
- # Attributes
3
- # -------------------------
2
+ # = Attributes
3
+ #
4
4
  # the sax parser passes an array of attributes along with each tag
5
5
  # attrs = ['href', 'http://www.example.com', 'style', 'background-color: snake;']
6
6
  #
7
7
  # Textile displays attributes in a certain way
8
8
  #
9
- # USAGE
10
- # ---------------------------
9
+ # = USAGE
10
+ #
11
11
  # Attributes.new(attrs).write
12
12
  #
13
+ #
14
+ # * colspan=2 => \2
15
+ # * rowspan=3 => /3
16
+ # * style='padding-left:1em' => (
17
+ # * style='padding-right:2em' => ))
18
+ # * style='text-align:right' => >
19
+ # * style='text-align:left' => <
20
+ # * style='text-align:center' => =
21
+ # * style='text-align:justify'=> <>
22
+ # * class = 'panthers' => (panthers)
23
+ # * id = 'banner' => (#banner)
24
+ # * class='this' id='that' => (this#that)
25
+ # * lang='fr' => [fr]
26
+ # * style='color:red' => {color:red}
27
+ #
13
28
  #
14
- # colspan=2 => \2
15
- # rowspan=3 => /3
16
- # style='padding-left:1em' => (
17
- # style='padding-right:2em' => ))
18
- # style='text-align:right' => >
19
- # style='text-align:left' => <
20
- # style='text-align:center' => =
21
- # style='text-align:justify'=> <>
22
- # class = 'panthers' => (panthers)
23
- # id = 'banner' => (#banner)
24
- # class='this' id='that' => (this#that)
25
- # lang='fr' => [fr]
26
- # style='color:red' => {color:red}
27
-
28
-
29
29
  class Attributes
30
-
30
+ # @param attrs [Array] formatted [key, value, key, value]
31
+ #
31
32
  def initialize(attrs)
32
33
  @attrs = attrs
33
34
  @attrs_hash = Hash[attrs]
@@ -44,7 +45,6 @@ class PinkShirt
44
45
  @styles_hash ||= {}
45
46
  end
46
47
 
47
-
48
48
  def write
49
49
  add = []
50
50
  add << colspan
@@ -56,11 +56,13 @@ class PinkShirt
56
56
  add << lang
57
57
  out = add.join
58
58
  return nil if out == ""
59
+
59
60
  out
60
61
  end
61
62
 
62
63
  def parse_styles
63
64
  return nil unless attrs['style']
65
+
64
66
  rules_list = attrs['style'].split(";").map{|rule|
65
67
  rule.split(":")
66
68
  }
@@ -89,13 +91,12 @@ class PinkShirt
89
91
  end
90
92
 
91
93
  nudges << text_align
92
-
93
94
  nudges
94
95
  end
95
96
 
96
97
  def steal_padding
97
-
98
98
  return nil unless attrs['style']
99
+
99
100
  left = case styles.delete('padding-left')
100
101
  when '1em'; "(" ;
101
102
  when '2em'; "((";
@@ -111,11 +112,11 @@ class PinkShirt
111
112
  end
112
113
 
113
114
  padding = "#{left}#{right}"
114
-
115
115
  end
116
116
 
117
117
  def colspan
118
118
  return nil unless attrs['colspan']
119
+
119
120
  width = attrs['colspan']
120
121
  colspan = ""
121
122
  colspan << "\\" #literal backslash
@@ -125,6 +126,7 @@ class PinkShirt
125
126
 
126
127
  def rowspan
127
128
  return nil unless attrs['rowspan']
129
+
128
130
  height = attrs['rowspan']
129
131
  colspan = '/' + "#{height}" if height
130
132
  end
@@ -142,6 +144,7 @@ class PinkShirt
142
144
  klass = attrs['class']
143
145
  id = attrs['id']
144
146
  return nil unless klass || id
147
+
145
148
  output = ""
146
149
  output += "("
147
150
  output += klass if klass
@@ -160,6 +163,7 @@ class PinkShirt
160
163
 
161
164
  def lang
162
165
  return nil unless attrs.include?('lang')
166
+
163
167
  output = ""
164
168
  output += "["
165
169
  output += attrs['lang']
@@ -1,26 +1,24 @@
1
1
  class PinkShirt
2
2
  # Gets rid of smart quotes, dashes and some pesky unicode
3
- # Usage
4
- # ---------------------
5
- # Entities.sanitize(input)
3
+ # = Usage
4
+ # Entities.sanitize(input)
6
5
  #
7
6
  class Entities
8
7
  REPLACEMENTS = {
9
- 8217 => "'", #single quote
10
- 8216 => "'", #left single quote
11
- 8220 => '"', #right double quote
12
- 8221 => '"', #left double quote
13
- 8211 => "-", #endash
14
- 8212 => "--", #emdash
8
+ 8217 => "'", #single quote
9
+ 8216 => "'", #left single quote
10
+ 8220 => '"', #right double quote
11
+ 8221 => '"', #left double quote
12
+ 8211 => "-", #endash
13
+ 8212 => "--", #emdash
15
14
  8230 => "...", #ellipsis
16
- 215 => "x", #times
17
- 8242 => "'", #inch
15
+ 215 => "x", #times
16
+ 8242 => "'", #inch
18
17
  174 => "(r)", #registered trademark
19
- 8482 => "(tm)", # trademark
18
+ 8482 => "(tm)",# trademark
20
19
  169 => "(c)", #copyright
21
20
  }
22
21
 
23
-
24
22
  def self.sanitize(string)
25
23
  string_chars = string.unpack("U*")
26
24
  string_chars.map! {|x| REPLACEMENTS[x] ? REPLACEMENTS[x].unpack('U*') : x}
@@ -1,21 +1,23 @@
1
1
  class PinkShirt
2
- #
2
+
3
+ ##
3
4
  # Nokogiri::Sax builds output as a long stream.
4
5
  # Output collects all the writes as an array, and then joins them when required
5
6
  # you can also lock it for writing.
6
7
  #
7
- # Usage
8
- # ------------------------
9
- # stream = Output.new
10
- # stream << 'goods... '
11
- # stream.inspect #=> ['goods... ']
12
- # stream.lock('suspicious tag')
13
- # stream << 'bad stuff'
14
- # stream.inspect #=> ['goods... ']
15
- # stream.unlock
16
- # stream << 'good again'
17
- # stream.inspect #=> ['goods... ', 'good again']
8
+ # = Usage
9
+ #
10
+ # stream = Output.new
11
+ # stream << 'goods... '
12
+ # stream.inspect #=> ['goods... ']
13
+ # stream.lock('suspicious tag')
14
+ # stream << 'bad stuff'
15
+ # stream.inspect #=> ['goods... ']
16
+ # stream.unlock
17
+ # stream << 'good again'
18
+ # stream.inspect #=> ['goods... ', 'good again']
18
19
  #
20
+
19
21
  class Output
20
22
  def initialize
21
23
  @contents = []
@@ -1,13 +1,16 @@
1
1
  class PinkShirt
2
2
  class SAX::Acronym < SAX::Base
3
3
  TAGS = %(acronym)
4
+
4
5
  def initialize(*args)
5
6
  @current_acronym = []
6
7
  super
7
8
  end
9
+
8
10
  def start_acronym attrs
9
11
  @current_acronym << attrs['title']
10
12
  end
13
+
11
14
  def end_acronym
12
15
  @output << "(#{@current_acronym.pop})"
13
16
  end
@@ -1,6 +1,7 @@
1
1
  class PinkShirt
2
2
  class SAX::Base
3
3
  TAGS = []
4
+
4
5
  def initialize(input, flags)
5
6
  @output = input
6
7
  @flags = flags
@@ -2,6 +2,7 @@ class PinkShirt
2
2
  class SAX::Basic < SAX::Base
3
3
  TAGS = %w(strong b em i cite del ins sub sup span code)
4
4
  attr_accessor :nospan
5
+
5
6
  def start_strong attrs
6
7
  @output << "*"
7
8
  @output << add_attributes(attrs) if add_attributes(attrs)
@@ -11,7 +12,6 @@ class PinkShirt
11
12
 
12
13
  def end_strong
13
14
  @output << "*"
14
-
15
15
  end
16
16
 
17
17
  def start_b attrs
@@ -1,6 +1,7 @@
1
1
  class PinkShirt
2
2
  class SAX::BlockLevel < SAX::Base
3
3
  TAGS = %w(p br h1 h2 h3 h4 h5 h6 div blockquote)
4
+
4
5
  def start_p attrs
5
6
  @output << "p#{add_attributes(attrs)}. " if add_attributes(attrs)
6
7
  end
@@ -1,6 +1,7 @@
1
1
  class PinkShirt
2
2
  class SAX::BoilerPlate < SAX::Base
3
3
  TAGS = %w(html body head)
4
+
4
5
  def start_html(attrs); end
5
6
  def end_html; end
6
7
  def start_body(attrs); end
@@ -1,6 +1,7 @@
1
1
  class PinkShirt
2
2
  class SAX::Images < SAX::Base
3
3
  TAGS = %(img)
4
+
4
5
  def start_img attrs
5
6
  title = attrs['alt'] || attrs['title']
6
7
  title = nil if title == "" || title == " "
@@ -10,6 +11,7 @@ class PinkShirt
10
11
  image += "!"
11
12
  @output << image
12
13
  end
14
+
13
15
  def end_img
14
16
 
15
17
  end
@@ -1,6 +1,7 @@
1
1
  class PinkShirt
2
2
  class SAX::Links < SAX::Base
3
3
  TAGS = %(a)
4
+
4
5
  def start_a attrs
5
6
  @link_info = attrs
6
7
  link = ""
@@ -8,6 +9,7 @@ class PinkShirt
8
9
  link += "(#{attrs['class']}). " if attrs['class']
9
10
  @output << link
10
11
  end
12
+
11
13
  def end_a
12
14
  link = ""
13
15
  link += " (#{@link_info['title']})" if @link_info['title']
@@ -1,11 +1,13 @@
1
1
  class PinkShirt
2
2
  class SAX::Lists < SAX::Base
3
3
  TAGS = %w(ul ol li dl dt dd)
4
+
4
5
  def initialize(*args)
5
6
  @last_depth = 0
6
7
  @nesting = []
7
8
  super
8
9
  end
10
+
9
11
  def start_ul(attrs)
10
12
  @nesting.push "ul"
11
13
  @in_ul = true
@@ -1,11 +1,12 @@
1
- class PinkShirt
2
-
1
+ class PinkShirt
3
2
  class SAX::Preformatted < SAX::Base
4
3
  TAGS = %(pre)
4
+
5
5
  def start_pre attrs
6
6
  @flags.pre = true
7
7
  @output << "pre#{add_attributes(attrs)}. "
8
8
  end
9
+
9
10
  def end_pre
10
11
  @flags.pre = false
11
12
  end
@@ -2,9 +2,11 @@ class PinkShirt
2
2
  # One does not textilize the contents of script tags, it is not done.
3
3
  class SAX::Script < SAX::Base
4
4
  TAGS = %(script)
5
+
5
6
  def start_script(attrs)
6
7
  @output.lock('script')
7
8
  end
9
+
8
10
  def end_script
9
11
  @output.unlock
10
12
  end
@@ -1,3 +1,3 @@
1
1
  class PinkShirt
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/pink_shirt.rb CHANGED
@@ -4,24 +4,23 @@ require 'nokogiri'
4
4
  # PinkShirt Undoes RedCloth
5
5
  #
6
6
  #
7
- # Usage
8
- # ---------------------------------
9
- # html = "stuff <b>goood</b> stuff"
10
- # PinkShirt.new('stuff').to_textile
7
+ # = Usage
8
+ # html = "stuff <b>goood</b> stuff"
9
+ # PinkShirt.new('stuff').to_textile
11
10
  #
12
- # Internals
13
- # ----------------------------------
11
+ # = Internals
12
+ #
14
13
  # PinkShirt uses a sax parser built on nokogiri
15
-
16
-
14
+ #
17
15
  class PinkShirt
18
-
16
+ # @param html [String]
19
17
  def initialize(html)
20
18
  @html = html
21
19
  @sax_syntax = PinkShirt::SAX.new
22
20
  @parser = Nokogiri::HTML::SAX::Parser.new(@sax_syntax)
23
21
  end
24
22
 
23
+ # renders to textile
25
24
  def to_textile
26
25
  @parser.parse(@html)do |config|
27
26
  config.replace_entities = false
data/pink_shirt.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
9
9
  s.email = ["graemeworthy@gmail.com"]
10
10
  s.homepage = ""
11
11
  s.summary = %q{An Html to Textile Converter}
12
- s.description = %q{Converts Html to Textile, or as some say 'html2textile', it's built on nokogiri''}
12
+ s.description = %q{Converts Html to Textile, or as some say 'html2textile', it's built on nokogiri}
13
13
 
14
14
  s.rubyforge_project = "pink_shirt"
15
15
 
@@ -10,22 +10,22 @@ Stress emphasis:
10
10
  text is typically styled as __italics__.
11
11
  input: You didn't actually _believe_ her, did you?
12
12
  output: <p>You didn&#8217;t actually <em>believe</em> her, did you?</p>
13
- # Stylistic offset:
14
- # Stylistic offset:
15
- # desc: To stylistically differentiate a word or phrase from the surrounding text
16
- # *without conveying any extra importance*, place two asterisks on either side. Uses
17
- # are key words in a document abstract, product names in a review, or other
18
- # spans of text whose typical typographic presentation is boldened.
19
- # input: |-
20
- # Search results for **Textile**:
13
+ Stylistic offset in links:
14
+ Stylistic offset in links:
15
+ desc: To stylistically differentiate a word or phrase from the surrounding text
16
+ *without conveying any extra importance*, place two asterisks on either side. Uses
17
+ are key words in a document abstract, product names in a review, or other
18
+ spans of text whose typical typographic presentation is boldened.
19
+ input: |-
20
+ Search results for **Textile**:
21
21
 
22
- # h4. ["**Textile** (markup language) - Wikipedia":http://en.wikipedia.org/wiki/Textile_(markup_language)]
22
+ h4. "**Textile** (markup language) - Wikipedia":http://en.wikipedia.org/wiki/Textile_(markup_language)
23
23
 
24
- # **Textile** is a lightweight markup language originally developed by Dean Allen and billed as a "humane Web text generator". **Textile** converts its marked-up text ...
25
- # output: |-
26
- # <p>Search results for <b>Textile</b>:</p>
27
- # <h4><a href="http://en.wikipedia.org/wiki/Textile_(markup_language)"><b>Textile</b> (markup language) &#8211; Wikipedia</a></h4>
28
- # <p><b>Textile</b> is a lightweight markup language originally developed by Dean Allen and billed as a &#8220;humane Web text generator&#8221;. <b>Textile</b> converts its marked-up text &#8230;</p>
24
+ **Textile** is a lightweight markup language originally developed by Dean Allen and billed as a "humane Web text generator". **Textile** converts its marked-up text ...
25
+ output: |-
26
+ <p>Search results for <b>Textile</b>:</p>
27
+ <h4><a href="http://en.wikipedia.org/wiki/Textile_(markup_language)"><b>Textile</b> (markup language) &#8211; Wikipedia</a></h4>
28
+ <p><b>Textile</b> is a lightweight markup language originally developed by Dean Allen and billed as a &#8220;humane Web text generator&#8221;. <b>Textile</b> converts its marked-up text &#8230;</p>
29
29
  Stylistic offset:
30
30
  Stylistic offset:
31
31
  desc: To stylistically differentiate a word or phrase from the surrounding text
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pink_shirt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-02-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: RedCloth
16
- requirement: &70119661660080 !ruby/object:Gem::Requirement
16
+ requirement: &70218567294800 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70119661660080
24
+ version_requirements: *70218567294800
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &70119661659440 !ruby/object:Gem::Requirement
27
+ requirement: &70218567294300 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70119661659440
35
+ version_requirements: *70218567294300
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: nokogiri
38
- requirement: &70119661658480 !ruby/object:Gem::Requirement
38
+ requirement: &70218567293720 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,9 +43,9 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70119661658480
46
+ version_requirements: *70218567293720
47
47
  description: Converts Html to Textile, or as some say 'html2textile', it's built on
48
- nokogiri''
48
+ nokogiri
49
49
  email:
50
50
  - graemeworthy@gmail.com
51
51
  executables: []
@@ -56,6 +56,7 @@ files:
56
56
  - Gemfile
57
57
  - Rakefile
58
58
  - Readme.txt
59
+ - changelog
59
60
  - lib/pink_shirt.rb
60
61
  - lib/pink_shirt/attributes.rb
61
62
  - lib/pink_shirt/entities.rb
@@ -128,3 +129,4 @@ test_files:
128
129
  - spec/textile-spec/paragraph_text.yaml
129
130
  - spec/textile-spec/phrase_modifiers.yaml
130
131
  - spec/textile_spec.rb
132
+ has_rdoc: