lesstile 0.3.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,2 +1,3 @@
1
1
  pkg
2
2
  doc
3
+ *.gemspec
data/History.txt CHANGED
@@ -9,3 +9,9 @@
9
9
  == 0.3 / 2008-04-17
10
10
 
11
11
  * Allow textile style links in text - "link":http://rhnh.net
12
+
13
+ == 1.0 / 2010-09-15
14
+
15
+ * Added #format_as_html method
16
+ * Switch to semantic versioning
17
+ * Removed dependency on Jeweler
data/README.txt CHANGED
@@ -3,7 +3,7 @@ by Xavier Shay (http://rhnh.net)
3
3
 
4
4
  == DESCRIPTION:
5
5
 
6
- Converts text formatted with an exceedingly simple markup language into XHTML (iron clad guarantee!) - perfect for comments on your blog. Textile isn't good for this because not only does it do too much (do commenters really need subscript?), but it can also output invalid HTML (try a <b> tag over multiple lines...). Whitelisting HTML is another option, but you still need some sort of parsing if you want syntax highlighting.
6
+ Converts text formatted with an exceedingly simple markup language into valid HTML (iron clad guarantee!) - perfect for comments on your blog. Textile isn't good for this because not only does it do too much (do commenters really need subscript?), but it can also output invalid HTML (try a <b> tag over multiple lines...). Whitelisting HTML is another option, but you still need some sort of parsing if you want syntax highlighting.
7
7
 
8
8
  Integrates with CodeRay for sexy syntax highlighting.
9
9
 
@@ -28,9 +28,12 @@ Integrates with CodeRay for sexy syntax highlighting.
28
28
  ---
29
29
  EOS
30
30
 
31
+ Lesstile.format_as_html(comment)
32
+ Lesstile.format_as_html(comment, :code_formatter => Lesstile::CodeRayFormatter) # Requires code ray
33
+ Lesstile.format_as_html(comment, :code_formatter => lambda {|code, lang| "Code in #{lang}: #{code}" })
34
+
35
+ # Also XHTML, for the old schoolers
31
36
  Lesstile.format_as_xhtml(comment)
32
- Lesstile.format_as_xhtml(comment, :code_formatter => Lesstile::CodeRayFormatter) # Requires code ray
33
- Lesstile.format_as_xhtml(comment, :code_formatter => lambda {|code, lang| "Code in #{lang}: #{code}" })
34
37
 
35
38
  == REQUIREMENTS:
36
39
 
@@ -41,7 +44,7 @@ Integrates with CodeRay for sexy syntax highlighting.
41
44
  sudo gem install lesstile # gem install
42
45
  git clone git://github.com/xaviershay/lesstile.git # go from source
43
46
 
44
- Tested on ruby 1.8.6-339, 1.8.7-160 and 1.9.1-rc2
47
+ Tested on ruby 1.8.6-339, 1.8.7-160, 1.9.1-rc2, and 1.9.2-p0
45
48
 
46
49
  == LICENSE:
47
50
 
data/Rakefile CHANGED
@@ -1,21 +1,3 @@
1
- begin
2
- require 'jeweler'
3
- Jeweler::Tasks.new do |gemspec|
4
- gemspec.name = "lesstile"
5
- gemspec.summary = "Format text using an exceedingly simple markup language - perfect for comments on your blog"
6
- gemspec.description = <<-EOS
7
- Converts text formatted with an exceedingly simple markup language into XHTML (iron clad guarantee!) - perfect for comments on your blog. Textile isn't good for this because not only does it do too much (do commenters really need subscript?), but it can also output invalid HTML (try a <b> tag over multiple lines...). Whitelisting HTML is another option, but you still need some sort of parsing if you want syntax highlighting.
8
-
9
- Integrates with CodeRay for sexy syntax highlighting.
10
- EOS
11
- gemspec.email = "contact@rhnh.net"
12
- gemspec.homepage = "http://github.com/xaviershay/lesstile"
13
- gemspec.authors = ["Xavier Shay"]
14
- end
15
- rescue LoadError
16
- puts "Jeweler not available. Install it with: sudo gem install jeweler"
17
- end
18
-
19
1
  require 'spec/rake/spectask'
20
2
  Spec::Rake::SpecTask.new do |t|
21
3
  t.warning = false
@@ -23,5 +5,5 @@ Spec::Rake::SpecTask.new do |t|
23
5
  t.spec_files = FileList['spec/spec_*.rb']
24
6
  end
25
7
 
26
- task :test => :spec
27
- # vim: syntax=Ruby
8
+ task :test => :spec
9
+ task :default => :spec
data/lib/lesstile.rb CHANGED
@@ -2,7 +2,7 @@ require 'cgi'
2
2
  require 'uri'
3
3
 
4
4
  class Lesstile
5
- VERSION = '0.3'
5
+ VERSION = '1.0'
6
6
 
7
7
  CodeDetectionRegex = /---\s*?([\w\s\._+()-]*?)\s*?\n(.*?)---\n/m
8
8
 
@@ -26,13 +26,25 @@ class Lesstile
26
26
  code = captures[1]
27
27
  lang = blank?(captures[0]) ? nil : captures[0].downcase.strip.intern
28
28
 
29
- output += options[:text_formatter][match.pre_match] + options[:code_formatter][code, lang]
29
+ output +=
30
+ options[:text_formatter][match.pre_match] +
31
+ options[:code_formatter][code, lang]
32
+
30
33
  text = match.post_match
31
34
  end
32
35
 
33
36
  output += options[:text_formatter][text.chomp]
34
37
  output
35
38
  end
39
+
40
+ # Returns lesstile formatted text as valid HTML5
41
+ #
42
+ # options (all optional):
43
+ # * <tt>text_formatter</tt>: A callback function used to format text.
44
+ # * <tt>code_formatter</tt>: A callback function used to format code. Typically used for syntax highlighting.
45
+ def format_as_html(text, options = {})
46
+ format_as_xhtml(text, options)
47
+ end
36
48
 
37
49
  def default_options
38
50
  {
@@ -62,5 +74,7 @@ class Lesstile
62
74
  end
63
75
 
64
76
  # A formatter that syntax highlights code using CodeRay
65
- CodeRayFormatter = lambda {|code, lang| CodeRay.scan(CGI::unescapeHTML(code), lang).html(:line_numbers => :table).div }
77
+ CodeRayFormatter = lambda {|code, lang|
78
+ CodeRay.scan(CGI::unescapeHTML(code), lang).html(:line_numbers => :table).div
79
+ }
66
80
  end
@@ -2,17 +2,7 @@ require 'rubygems'
2
2
  require 'spec'
3
3
  require File.dirname(__FILE__) + '/../lib/lesstile'
4
4
 
5
- describe "Lesstile#format_as_xhtml" do
6
- before(:all) do
7
- @lesstile = Lesstile
8
- @format = lambda {|text|
9
- @lesstile.format_as_xhtml(text,
10
- :code_formatter => lambda {|code, lang| "|#{"(#{lang})" if lang}#{code}|" },
11
- :text_formatter => lambda {|text| text }
12
- )
13
- }
14
- end
15
-
5
+ describe 'an html formatter', :shared => true do
16
6
  it "normal text unchanged" do
17
7
  @format["hello"].should == "hello"
18
8
  end
@@ -63,6 +53,34 @@ describe "Lesstile#format_as_xhtml" do
63
53
  end
64
54
  end
65
55
 
56
+ describe "Lesstile#format_as_xhtml" do
57
+ before(:all) do
58
+ @lesstile = Lesstile
59
+ @format = lambda {|text|
60
+ @lesstile.format_as_xhtml(text,
61
+ :code_formatter => lambda {|code, lang| "|#{"(#{lang})" if lang}#{code}|" },
62
+ :text_formatter => lambda {|text| text }
63
+ )
64
+ }
65
+ end
66
+
67
+ it_should_behave_like 'an html formatter'
68
+ end
69
+
70
+ describe "Lesstile#format_as_html" do
71
+ before(:all) do
72
+ @lesstile = Lesstile
73
+ @format = lambda {|text|
74
+ @lesstile.format_as_html(text,
75
+ :code_formatter => lambda {|code, lang| "|#{"(#{lang})" if lang}#{code}|" },
76
+ :text_formatter => lambda {|text| text }
77
+ )
78
+ }
79
+ end
80
+
81
+ it_should_behave_like 'an html formatter'
82
+ end
83
+
66
84
  describe 'Lesstile default text formatter' do
67
85
  before(:all) do
68
86
  @format = lambda {|text| Lesstile.default_options[:text_formatter][text] }
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lesstile
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ hash: 23
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
5
11
  platform: ruby
6
12
  authors:
7
13
  - Xavier Shay
@@ -9,12 +15,12 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2009-10-28 00:00:00 +11:00
18
+ date: 2010-09-15 00:00:00 +01:00
13
19
  default_executable:
14
20
  dependencies: []
15
21
 
16
22
  description: |
17
- Converts text formatted with an exceedingly simple markup language into XHTML (iron clad guarantee!) - perfect for comments on your blog. Textile isn't good for this because not only does it do too much (do commenters really need subscript?), but it can also output invalid HTML (try a <b> tag over multiple lines...). Whitelisting HTML is another option, but you still need some sort of parsing if you want syntax highlighting.
23
+ Converts text formatted with an exceedingly simple markup language into valid HTML (iron clad guarantee!) - perfect for comments on your blog. Textile isn't good for this because not only does it do too much (do commenters really need subscript?), but it can also output invalid HTML (try a <b> tag over multiple lines...). Whitelisting HTML is another option, but you still need some sort of parsing if you want syntax highlighting.
18
24
 
19
25
  Integrates with CodeRay for sexy syntax highlighting.
20
26
 
@@ -31,7 +37,6 @@ files:
31
37
  - Manifest.txt
32
38
  - README.txt
33
39
  - Rakefile
34
- - VERSION
35
40
  - lib/lesstile.rb
36
41
  - spec/spec_lesstile.rb
37
42
  has_rdoc: true
@@ -44,21 +49,27 @@ rdoc_options:
44
49
  require_paths:
45
50
  - lib
46
51
  required_ruby_version: !ruby/object:Gem::Requirement
52
+ none: false
47
53
  requirements:
48
54
  - - ">="
49
55
  - !ruby/object:Gem::Version
56
+ hash: 3
57
+ segments:
58
+ - 0
50
59
  version: "0"
51
- version:
52
60
  required_rubygems_version: !ruby/object:Gem::Requirement
61
+ none: false
53
62
  requirements:
54
63
  - - ">="
55
64
  - !ruby/object:Gem::Version
65
+ hash: 3
66
+ segments:
67
+ - 0
56
68
  version: "0"
57
- version:
58
69
  requirements: []
59
70
 
60
71
  rubyforge_project:
61
- rubygems_version: 1.3.4
72
+ rubygems_version: 1.3.7
62
73
  signing_key:
63
74
  specification_version: 3
64
75
  summary: Format text using an exceedingly simple markup language - perfect for comments on your blog
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.3.0