lesstile 0.2 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -5,3 +5,7 @@
5
5
  == 0.2 / 2008-02-08
6
6
 
7
7
  * Remove dependency on facets
8
+
9
+ == 0.3 / 2008-04-17
10
+
11
+ * Allow textile style links in text - "link":http://rhnh.net
data/Manifest.txt CHANGED
@@ -2,6 +2,5 @@ History.txt
2
2
  Manifest.txt
3
3
  README.txt
4
4
  Rakefile
5
- bin/lesstile
6
5
  lib/lesstile.rb
7
6
  spec/spec_lesstile.rb
data/README.txt CHANGED
@@ -10,6 +10,7 @@ Integrates with CodeRay for sexy syntax highlighting.
10
10
  == SYNOPSIS:
11
11
 
12
12
  comment = <<-EOS
13
+ "Ego Link":http://rhnh.net
13
14
  Wow, this post is awesome. I'd implement it like this:
14
15
 
15
16
  --- Ruby
@@ -35,9 +36,10 @@ Integrates with CodeRay for sexy syntax highlighting.
35
36
 
36
37
  * CodeRay (optional)
37
38
 
38
- == INSTALL:
39
+ == INSTALL (pick one):
39
40
 
40
- sudo gem install lesstile
41
+ sudo gem install lesstile # gem install
42
+ git clone git://github.com/xaviershay/lesstile.git # go from source
41
43
 
42
44
  == LICENSE:
43
45
 
data/lib/lesstile.rb CHANGED
@@ -1,7 +1,8 @@
1
1
  require 'cgi'
2
+ require 'uri'
2
3
 
3
4
  class Lesstile
4
- VERSION = '0.2'
5
+ VERSION = '0.3'
5
6
 
6
7
  class << self
7
8
  # Returns lesstile formatted text as valid XHTML
@@ -35,7 +36,26 @@ class Lesstile
35
36
  def default_options
36
37
  {
37
38
  :code_formatter => lambda {|code, lang| "<pre><code>#{code}</code></pre>" },
38
- :text_formatter => lambda {|text| text.gsub(/\n/, "<br />\n") }
39
+ :text_formatter => lambda {|text|
40
+ text = text.gsub(/\n/, "<br />\n")
41
+ uris = URI.extract(text)
42
+
43
+ buffer = ""
44
+ uris.each do |uri|
45
+ pivot = text.index(uri)
46
+ pre = text[0..pivot-1]
47
+ m = pre.match(/&quot;(.*)&quot;:$/)
48
+ link = m ? m.captures.first : nil
49
+ if link
50
+ buffer += m.pre_match + "<a href='#{uri.to_s}'>#{link}</a>"
51
+ else
52
+ buffer += pre + uri
53
+ end
54
+ text = text[pivot+uri.length..-1]
55
+ end
56
+ buffer += text
57
+ buffer
58
+ }
39
59
  }
40
60
  end
41
61
 
@@ -44,6 +44,21 @@ describe "Lesstile#format_as_xhtml" do
44
44
  it 'escapes html' do
45
45
  @format["<a>&---\nyo<---"].should == "&lt;a&gt;&amp;|yo&lt;|"
46
46
  end
47
+
48
+ it 'escapes quotes' do
49
+ @format['"'].should == "&quot;"
50
+ end
51
+ end
52
+
53
+ describe 'Lesstile default text formatter' do
54
+ before(:all) do
55
+ @format = lambda {|text| Lesstile.default_options[:text_formatter][text] }
56
+ end
57
+
58
+ it 'recognises links in text' do
59
+ @format['&quot;a link&quot;:http://example.com &quot;&lt;link&quot;:http://example.com linkage'].should ==
60
+ "<a href='http://example.com'>a link</a> <a href='http://example.com'>&lt;link</a> linkage"
61
+ end
47
62
  end
48
63
 
49
64
  describe "Lesstile#format_with_xhtml with default formatters" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lesstile
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.2"
4
+ version: "0.3"
5
5
  platform: ""
6
6
  authors:
7
7
  - Xavier Shay
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-02-08 00:00:00 +11:00
12
+ date: 2008-04-17 00:00:00 +10:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -19,12 +19,12 @@ dependencies:
19
19
  requirements:
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: 1.4.0
22
+ version: 1.5.1
23
23
  version:
24
- description: "Integrates with CodeRay for sexy syntax highlighting. == SYNOPSIS: comment = <<-EOS Wow, this post is awesome. I'd implement it like this: --- Ruby def hello_world puts \"hello world!\" end ---"
24
+ description: "Integrates with CodeRay for sexy syntax highlighting. == SYNOPSIS: comment = <<-EOS \"Ego Link\":http://rhnh.net Wow, this post is awesome. I'd implement it like this: --- Ruby def hello_world puts \"hello world!\" end ---"
25
25
  email: xavier@rhnh.net
26
- executables:
27
- - lesstile
26
+ executables: []
27
+
28
28
  extensions: []
29
29
 
30
30
  extra_rdoc_files:
@@ -36,7 +36,6 @@ files:
36
36
  - Manifest.txt
37
37
  - README.txt
38
38
  - Rakefile
39
- - bin/lesstile
40
39
  - lib/lesstile.rb
41
40
  - spec/spec_lesstile.rb
42
41
  has_rdoc: true
data/bin/lesstile DELETED
File without changes