vidibus-textile 0.1.0

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,22 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
22
+ .bundle
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --format nested
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "http://gemcutter.org"
2
+ gem "bundler", "~> 1.0.0"
3
+ gem "RedCloth"
4
+ gem "activesupport", "~> 3.0.0"
5
+ gem "actionpack", "~> 3.0.0"
6
+ gem "rspec", "~> 2.0.0.beta.20"
7
+ gem "rr"
8
+ gem "relevance-rcov"
data/Gemfile.lock ADDED
@@ -0,0 +1,55 @@
1
+ GEM
2
+ remote: http://gemcutter.org/
3
+ specs:
4
+ RedCloth (4.2.3)
5
+ abstract (1.0.0)
6
+ actionpack (3.0.0)
7
+ activemodel (= 3.0.0)
8
+ activesupport (= 3.0.0)
9
+ builder (~> 2.1.2)
10
+ erubis (~> 2.6.6)
11
+ i18n (~> 0.4.1)
12
+ rack (~> 1.2.1)
13
+ rack-mount (~> 0.6.12)
14
+ rack-test (~> 0.5.4)
15
+ tzinfo (~> 0.3.23)
16
+ activemodel (3.0.0)
17
+ activesupport (= 3.0.0)
18
+ builder (~> 2.1.2)
19
+ i18n (~> 0.4.1)
20
+ activesupport (3.0.0)
21
+ builder (2.1.2)
22
+ diff-lcs (1.1.2)
23
+ erubis (2.6.6)
24
+ abstract (>= 1.0.0)
25
+ i18n (0.4.1)
26
+ rack (1.2.1)
27
+ rack-mount (0.6.13)
28
+ rack (>= 1.0.0)
29
+ rack-test (0.5.6)
30
+ rack (>= 1.0)
31
+ relevance-rcov (0.9.2.1)
32
+ rr (1.0.0)
33
+ rspec (2.0.0.beta.22)
34
+ rspec-core (= 2.0.0.beta.22)
35
+ rspec-expectations (= 2.0.0.beta.22)
36
+ rspec-mocks (= 2.0.0.beta.22)
37
+ rspec-core (2.0.0.beta.22)
38
+ rspec-expectations (2.0.0.beta.22)
39
+ diff-lcs (>= 1.1.2)
40
+ rspec-mocks (2.0.0.beta.22)
41
+ rspec-core (= 2.0.0.beta.22)
42
+ rspec-expectations (= 2.0.0.beta.22)
43
+ tzinfo (0.3.23)
44
+
45
+ PLATFORMS
46
+ ruby
47
+
48
+ DEPENDENCIES
49
+ RedCloth
50
+ actionpack (~> 3.0.0)
51
+ activesupport (~> 3.0.0)
52
+ bundler (~> 1.0.0)
53
+ relevance-rcov
54
+ rr
55
+ rspec (~> 2.0.0.beta.20)
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Andre Pankratz
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,39 @@
1
+ = vidibus-textile
2
+
3
+ Basically, this is a wrapper for RedCloth with some extensions. It is inspired by the acts_as_textiled plugin, but without the model integration (for now).
4
+
5
+ This gem is part of the open source SOA framework Vidibus: http://vidibus.org.
6
+
7
+
8
+ == Usage
9
+
10
+ The basic two methods are:
11
+
12
+ #to_html (provided by RedCloth)
13
+ Vidibus::Textile.new('Some *say*, "love":http://doit.xxx is a _river_.').to_html
14
+ # => '<p>Some <strong>say</strong>, <a href="http://doit.xxx">love</a> is a <em>river</em>.</p>'
15
+
16
+ #to_text
17
+ Vidibus::Textile.new('Some *say*, "love":http://doit.xxx is a _river_.').to_text
18
+ # => "Some say, love is a river."
19
+
20
+ The method #to_text will return a plain text version of textile content but keep newlines intact. However, if
21
+ you just want a stripped version without newlines, provide the option :plain => true
22
+
23
+ #to_text with :plain => true
24
+ Vidibus::Textile.new("Super\nTrouper").to_text(:plain => true)
25
+ # => "Super Trouper"
26
+
27
+
28
+ == View helper
29
+
30
+ For your convenience, the view helper ##stripped is available (as couterpart for Rails' ##textilize).
31
+
32
+ # In you view...
33
+ stripped("*Super*\nTrouper", :plain => true)
34
+ # => "Super Trouper"
35
+
36
+
37
+ == Copyright
38
+
39
+ Copyright (c) 2010 Andre Pankratz. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,38 @@
1
+ require "rubygems"
2
+ require "rake"
3
+ require "rake/rdoctask"
4
+ require "rspec"
5
+ require "rspec/core/rake_task"
6
+
7
+ begin
8
+ require "jeweler"
9
+ Jeweler::Tasks.new do |gem|
10
+ gem.name = "vidibus-textile"
11
+ gem.summary = %Q{Wrapper for RedCloth with extensions.}
12
+ gem.description = %Q{Provides textile formatting through RedCloth and adds methods for getting plain text version of textile markup.}
13
+ gem.email = "andre@vidibus.com"
14
+ gem.homepage = "http://github.com/vidibus/vidibus-textile"
15
+ gem.authors = ["Andre Pankratz"]
16
+ gem.add_dependency "RedCloth"
17
+ gem.add_dependency "activesupport"
18
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
19
+ end
20
+ Jeweler::GemcutterTasks.new
21
+ rescue LoadError
22
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
23
+ end
24
+
25
+ Rspec::Core::RakeTask.new(:rcov) do |t|
26
+ t.pattern = "spec/**/*_spec.rb"
27
+ t.rcov = true
28
+ t.rcov_opts = ["--exclude", "^spec,/gems/", "-Ispec"]
29
+ end
30
+
31
+ Rake::RDocTask.new do |rdoc|
32
+ version = File.exist?("VERSION") ? File.read("VERSION") : ""
33
+ rdoc.rdoc_dir = "rdoc"
34
+ rdoc.title = "vidibus-textile #{version}"
35
+ rdoc.rdoc_files.include("README*")
36
+ rdoc.rdoc_files.include("lib/**/*.rb")
37
+ rdoc.options << "--charset=utf-8"
38
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,15 @@
1
+ module Vidibus
2
+ module Textile
3
+ module Extensions
4
+ module View
5
+ extend ActiveSupport::Concern
6
+
7
+ # Returns plain text without markup.
8
+ # If option :plain is true, newlines will be removed.
9
+ def stripped(string, options = {})
10
+ string ? Vidibus::Textile.new(string).to_text(options) : ""
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ require "textile/extensions/view"
2
+
3
+ ActiveSupport.on_load(:action_view) do
4
+ include Vidibus::Textile::Extensions::View
5
+ end
@@ -0,0 +1,72 @@
1
+ require "textile/extensions"
2
+
3
+ module Vidibus
4
+ module Textile
5
+
6
+ # A convenience method for creating a new TextileDoc. See
7
+ # RedCloth::TextileDoc.
8
+ def self.new(*args, &block)
9
+ Textile::Doc.new(*args, &block)
10
+ end
11
+
12
+ # Include extension modules (if any) in TextileDoc.
13
+ def self.include(*args)
14
+ Textile::Doc.send(:include, *args)
15
+ end
16
+
17
+ class Doc < ::RedCloth::TextileDoc
18
+
19
+ # Returns plain text without markup.
20
+ # If option :plain is true, newlines will be removed.
21
+ def to_text(options = {})
22
+ text = strip_html(self.to_html)
23
+ if options[:plain] == true
24
+ return strip_newlines(text)
25
+ end
26
+ text
27
+ end
28
+
29
+ private
30
+
31
+ # Remove html tags and redcloth glyphs from input string.
32
+ def strip_html(input)
33
+ input.dup.gsub(html_regexp, '').tap do |h|
34
+ for entity, char in redcloth_glyphs
35
+ h.gsub!(entity, char)
36
+ end
37
+ end
38
+ end
39
+
40
+ # Replace newlines by white space.
41
+ def strip_newlines(input)
42
+ input.gsub(/(\r?\n)+/," ")
43
+ end
44
+
45
+ # Returns a list of RedCloth conversions of special chars.
46
+ def redcloth_glyphs
47
+ {
48
+ "&#8217;" => "'",
49
+ "&#8216" => "'",
50
+ "&lt;" => "<",
51
+ "&gt;" => ">",
52
+ "&#8221;" => '"',
53
+ "&#8220;" => '"',
54
+ "&#8230;" => "...",
55
+ "\1&#8212;" => "--",
56
+ " &rarr; " => "->",
57
+ " &#8211; " => "-",
58
+ "&#215;" => "-",
59
+ "&#8482;" => "(TM)",
60
+ "&#174;" => "(R)",
61
+ "&#169;" => "(C)",
62
+ "&amp;" => "&"
63
+ }.freeze
64
+ end
65
+
66
+ # Returns regular expression to identifiy html tags.
67
+ def html_regexp
68
+ /<(?:[^>"']+|"(?:\\.|[^\\"]+)*"|'(?:\\.|[^\\']+)*')*>/xm
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,5 @@
1
+ require "redcloth"
2
+ require "active_support"
3
+
4
+ $:.unshift(File.join(File.dirname(__FILE__), "..", "lib", "vidibus"))
5
+ require "textile"
@@ -0,0 +1,10 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
3
+
4
+ require "rubygems"
5
+ require "rspec"
6
+ require "vidibus-textile"
7
+
8
+ RSpec.configure do |config|
9
+ config.mock_with :rr
10
+ end
@@ -0,0 +1,25 @@
1
+ require "spec_helper.rb"
2
+ require "action_view"
3
+
4
+ describe ActionView::Base do
5
+ describe "#stripped" do
6
+ it "should call Vidibus::Textile::Doc#to_text" do
7
+ mock.any_instance_of(Vidibus::Textile::Doc).to_text({})
8
+ subject.stripped("something")
9
+ end
10
+
11
+ it "should accept options" do
12
+ mock.any_instance_of(Vidibus::Textile::Doc).to_text(:plain => true)
13
+ subject.stripped("something", :plain => true)
14
+ end
15
+
16
+ it "should work as intended" do
17
+ subject.stripped('Some *say*, "love":http://doit.xxx is a _river_.').should eql("Some say, love is a river.")
18
+ end
19
+
20
+ it "should handle empty content" do
21
+ dont_allow.any_instance_of(Vidibus::Textile::Doc).to_text({})
22
+ subject.stripped(nil).should eql("")
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,32 @@
1
+ require "spec_helper"
2
+
3
+ describe Vidibus::Textile do
4
+ describe "#to_html" do
5
+ it "should contain textile content as html" do
6
+ textile = Vidibus::Textile.new('Some *say*, "love":http://doit.xxx is a _river_.')
7
+ textile.to_html.should eql('<p>Some <strong>say</strong>, <a href="http://doit.xxx">love</a> is a <em>river</em>.</p>')
8
+ end
9
+ end
10
+
11
+ describe "#to_text" do
12
+ it "should not contain plain description without html or textile markup" do
13
+ textile = Vidibus::Textile.new('Some *say*, "love":http://doit.xxx is a _river_.')
14
+ textile.to_text.should eql("Some say, love is a river.")
15
+ end
16
+
17
+ it "should not contain RedCloth glyphs" do
18
+ textile = Vidibus::Textile.new(%(<Chief's> "Special" & Sauce (C)))
19
+ textile.to_text.should eql(%(<Chief's> "Special" & Sauce (C)))
20
+ end
21
+
22
+ it "should contain newlines" do
23
+ textile = Vidibus::Textile.new("Super\nTrouper")
24
+ textile.to_text.should eql("Super\nTrouper")
25
+ end
26
+
27
+ it "should not contain newlines if option :plain is true" do
28
+ textile = Vidibus::Textile.new("Super\nTrouper")
29
+ textile.to_text(:plain => true).should eql("Super Trouper")
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,65 @@
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{vidibus-textile}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Andre Pankratz"]
12
+ s.date = %q{2010-10-01}
13
+ s.description = %q{Provides textile formatting through RedCloth and adds methods for getting plain text version of textile markup.}
14
+ s.email = %q{andre@vidibus.com}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ ".rspec",
23
+ "Gemfile",
24
+ "Gemfile.lock",
25
+ "LICENSE",
26
+ "README.rdoc",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "lib/vidibus-textile.rb",
30
+ "lib/vidibus/textile.rb",
31
+ "lib/vidibus/textile/extensions.rb",
32
+ "lib/vidibus/textile/extensions/view.rb",
33
+ "spec/spec_helper.rb",
34
+ "spec/vidibus/textile/action_view_spec.rb",
35
+ "spec/vidibus/textile_spec.rb",
36
+ "vidibus-textile.gemspec"
37
+ ]
38
+ s.homepage = %q{http://github.com/vidibus/vidibus-textile}
39
+ s.rdoc_options = ["--charset=UTF-8"]
40
+ s.require_paths = ["lib"]
41
+ s.rubygems_version = %q{1.3.7}
42
+ s.summary = %q{Wrapper for RedCloth with extensions.}
43
+ s.test_files = [
44
+ "spec/spec_helper.rb",
45
+ "spec/vidibus/textile/action_view_spec.rb",
46
+ "spec/vidibus/textile_spec.rb"
47
+ ]
48
+
49
+ if s.respond_to? :specification_version then
50
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
51
+ s.specification_version = 3
52
+
53
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
54
+ s.add_runtime_dependency(%q<RedCloth>, [">= 0"])
55
+ s.add_runtime_dependency(%q<activesupport>, [">= 0"])
56
+ else
57
+ s.add_dependency(%q<RedCloth>, [">= 0"])
58
+ s.add_dependency(%q<activesupport>, [">= 0"])
59
+ end
60
+ else
61
+ s.add_dependency(%q<RedCloth>, [">= 0"])
62
+ s.add_dependency(%q<activesupport>, [">= 0"])
63
+ end
64
+ end
65
+
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vidibus-textile
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Andre Pankratz
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-10-01 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: RedCloth
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: activesupport
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :runtime
48
+ version_requirements: *id002
49
+ description: Provides textile formatting through RedCloth and adds methods for getting plain text version of textile markup.
50
+ email: andre@vidibus.com
51
+ executables: []
52
+
53
+ extensions: []
54
+
55
+ extra_rdoc_files:
56
+ - LICENSE
57
+ - README.rdoc
58
+ files:
59
+ - .document
60
+ - .gitignore
61
+ - .rspec
62
+ - Gemfile
63
+ - Gemfile.lock
64
+ - LICENSE
65
+ - README.rdoc
66
+ - Rakefile
67
+ - VERSION
68
+ - lib/vidibus-textile.rb
69
+ - lib/vidibus/textile.rb
70
+ - lib/vidibus/textile/extensions.rb
71
+ - lib/vidibus/textile/extensions/view.rb
72
+ - spec/spec_helper.rb
73
+ - spec/vidibus/textile/action_view_spec.rb
74
+ - spec/vidibus/textile_spec.rb
75
+ - vidibus-textile.gemspec
76
+ has_rdoc: true
77
+ homepage: http://github.com/vidibus/vidibus-textile
78
+ licenses: []
79
+
80
+ post_install_message:
81
+ rdoc_options:
82
+ - --charset=UTF-8
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ hash: 3
91
+ segments:
92
+ - 0
93
+ version: "0"
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ none: false
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ hash: 3
100
+ segments:
101
+ - 0
102
+ version: "0"
103
+ requirements: []
104
+
105
+ rubyforge_project:
106
+ rubygems_version: 1.3.7
107
+ signing_key:
108
+ specification_version: 3
109
+ summary: Wrapper for RedCloth with extensions.
110
+ test_files:
111
+ - spec/spec_helper.rb
112
+ - spec/vidibus/textile/action_view_spec.rb
113
+ - spec/vidibus/textile_spec.rb