velvet_rope 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/CHANGELOG ADDED
@@ -0,0 +1,3 @@
1
+ ## v0.0.1
2
+
3
+ * Initial release
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in redcarpet_pygments.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Sean Gaffney
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,121 @@
1
+ # VelvetRope
2
+
3
+ VelvetRope is a renderer to complement and enhance Redcarpet's default HTML
4
+ renderer. For now, it adds support for emoji and syntax-highlighting.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'velvet_rope'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install velvet_rope
21
+
22
+ ## Usage
23
+
24
+ ### Syntax Highlighting
25
+
26
+ VelvetRope uses [pygments.rb](https://github.com/tmm1/pygments.rb) to provide
27
+ syntax highlighting support. In order to turn this on, just pass the
28
+ `highlight_syntax` option into VelvetRope on instantiation.
29
+
30
+ ```ruby
31
+ Redcarpet::Render::VelvetRope.new(:highlight_syntax => true)
32
+ ```
33
+
34
+ You will need to generate the CSS for the Pygments theme that you would like to
35
+ use for highlighting. You can find instructions on how to do that in the
36
+ [pygments.rb documentation](https://github.com/tmm1/pygments.rb#usag://github.com/tmm1/pygments.rb#usage).
37
+
38
+ ### Emoji
39
+
40
+ VelvetRope uses [gemoji](https://github.com/github/gemoji) to provide emoji
41
+ support. In order to turn this on, just pass the `emoji` option into VelvetRope
42
+ on instantiation.
43
+
44
+ ```ruby
45
+ Redcarpet::Render::VelvetRope.new(:emoji => true)
46
+ ```
47
+
48
+ You will need to add the emoji images to your app. There are instructions on how
49
+ to do so in the [gemoji documentation](https://github.com/github/gemoji#installation).
50
+
51
+ Also, the default template for emoji images is:
52
+
53
+
54
+ ```ruby
55
+ '<img alt="' + name + '" src="' + "/images/emoji/#{name}.png" + '" style="vertical-align:middle" width="20" height="20" />'
56
+ ```
57
+
58
+ If you would like to define your own template, you could do something like the
59
+ following in an initializer:
60
+
61
+ ```ruby
62
+ module Redcarpet
63
+ module Render
64
+ class VelvetRope < HTML
65
+ def emoji_template(name)
66
+ '<img class="emoji" src="' + "/images/emoji/#{name}.png" + '" width="20" height="20" />'
67
+ end
68
+ end
69
+ end
70
+ end
71
+ ```
72
+
73
+ ### HTML? But what about XHTML?!
74
+
75
+ Fear not, my friend. Just pass the `xhtml` option into the VelvetRope renderer on
76
+ instantiation.
77
+
78
+ ```ruby
79
+ Redcarpet::Render::VelvetRope.new(:xhtml => true)
80
+ ```
81
+
82
+ Redcarpet's XHTML renderer is just a shortcut for this very option.
83
+
84
+ ## TODO
85
+
86
+ Create rake tasks to simplify setup and installation of Pygments themes and emoji
87
+ image files.
88
+
89
+ ## Contributing
90
+
91
+ 1. Fork it
92
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
93
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
94
+ 4. Push to the branch (`git push origin my-new-feature`)
95
+ 5. Create new Pull Request
96
+
97
+ ## Licensing
98
+
99
+ VelvetRope is written by [Sean Gaffney](http://seangaffney.cc) and is under the
100
+ MIT License.
101
+
102
+ The MIT License (MIT)
103
+
104
+ Copyright (c) Ted Nyman and Aman Gupta, 2012-2013
105
+
106
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
107
+ this software and associated documentation files (the "Software"), to deal in the
108
+ Software without restriction, including without limitation the rights to use,
109
+ copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
110
+ Software, and to permit persons to whom the Software is furnished to do so,
111
+ subject to the following conditions:
112
+
113
+ The above copyright notice and this permission notice shall be included in all
114
+ copies or substantial portions of the Software.
115
+
116
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
117
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
118
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
119
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
120
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
121
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+ task :default => :spec
@@ -0,0 +1,45 @@
1
+ require "redcarpet"
2
+ require "pygments.rb"
3
+ require "gemoji"
4
+
5
+ module Redcarpet
6
+ module Render
7
+ class VelvetRope < HTML
8
+
9
+ def initialize(extensions={})
10
+ @extensions ||= {}
11
+ @extensions[:highlight_syntax] = extensions.delete(:highlight_syntax) || false
12
+ @extensions[:emoji] = extensions.delete(:emoji) || false
13
+
14
+ # This is ugly, but is a workaround for Redcarpet not handling `super`
15
+ # as it is a wrapper for the implementation written in C
16
+ if @extensions[:highlight_syntax]
17
+ self.class.send(:define_method, :block_code) do |code, language|
18
+ Pygments.highlight(code, :lexer => language)
19
+ end
20
+ end
21
+
22
+ # `super` however DOES work in this intializer...
23
+ super(extensions)
24
+ end
25
+
26
+ def postprocess(document)
27
+ if @extensions[:emoji]
28
+ document.gsub!(/:([a-z0-9\+\-_]+):/) do |match|
29
+ if Emoji.names.include?($1)
30
+ emoji_template($1)
31
+ else
32
+ match
33
+ end
34
+ end
35
+ end
36
+ document
37
+ end
38
+
39
+ def emoji_template(name)
40
+ '<img alt="' + name + '" src="' + "/images/emoji/#{name}.png" + '" style="vertical-align:middle" width="20" height="20" />'
41
+ end
42
+
43
+ end
44
+ end
45
+ end
@@ -0,0 +1 @@
1
+ require 'velvet_rope'
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Redcarpet::Render::VelvetRope do
5
+
6
+ context 'with emoji option set to true' do
7
+ let(:markdown) { Redcarpet::Markdown.new(Redcarpet::Render::VelvetRope.new(:emoji => true)) }
8
+
9
+ it 'renders emoji characters' do
10
+ content = 'This should be a :smiley: face.'
11
+
12
+ expected = '<p>This should be a <img alt="smiley" src="/images/emoji/smiley.png" style="vertical-align:middle" width="20" height="20" /> face.</p>' + "\n"
13
+ markdown.render(content).should eq(expected)
14
+ end
15
+ end
16
+
17
+ context 'with highlight_syntax option set to true' do
18
+ let(:markdown) { Redcarpet::Markdown.new(Redcarpet::Render::VelvetRope.new(:highlight_syntax => true)) }
19
+
20
+ it 'renders highlighted syntax for normal code blocks' do
21
+ content = <<-EOS
22
+ This is an example of some Ruby code:
23
+
24
+ def my_method
25
+ 'my string'.uppercase
26
+ end
27
+ EOS
28
+
29
+ expected = %{<p>This is an example of some Ruby code:</p>\n<div class=\"highlight\"><pre><span class=\"n\">def</span> <span class=\"n\">my_method</span>\n <span class=\"s\">&#39;my string&#39;</span><span class=\"p\">.</span><span class=\"n\">uppercase</span>\n<span class=\"k\">end</span>\n</pre></div>}
30
+ markdown.render(content).should eq(expected)
31
+ end
32
+ end
33
+
34
+ context 'with highlight_syntax option set to true and with fenced_code_blocks turned on' do
35
+ let(:markdown) { Redcarpet::Markdown.new(Redcarpet::Render::VelvetRope.new(:highlight_syntax => true), :fenced_code_blocks => true) }
36
+
37
+ it 'renders highlighted syntax for fenced code blocks' do
38
+ content = <<-EOS
39
+ This is an example of some Ruby code in a fenced code block:
40
+
41
+ ```ruby
42
+ def my_method
43
+ 'my string'.uppercase
44
+ end
45
+ ```
46
+ EOS
47
+
48
+ expected = %{<p>This is an example of some Ruby code in a fenced code block:</p>\n<div class=\"highlight\"><pre><span class=\"k\">def</span> <span class=\"nf\">my_method</span>\n <span class=\"s1\">&#39;my string&#39;</span><span class=\"o\">.</span><span class=\"n\">uppercase</span>\n<span class=\"k\">end</span>\n</pre></div>}
49
+ markdown.render(content).should eq(expected)
50
+ end
51
+ end
52
+
53
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = "velvet_rope"
7
+ gem.version = "0.0.1"
8
+ gem.authors = ["Sean Gaffney"]
9
+ gem.email = ["sean@seangaffney.cc"]
10
+ gem.description = %q{VelvetRope is a renderer to complement and enhance Redcarpet's default HTML renderer. It adds support for emoji and syntax-highlighting.}
11
+ gem.summary = %q{Provides out-of-the-box syntax-highlighting and emoji support for the Redcarpet markdown library.}
12
+ gem.homepage = "http://github.com/seangaffney/velvet_rope"
13
+
14
+ gem.files = `git ls-files`.split($/)
15
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
16
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
+ gem.require_paths = ["lib"]
18
+
19
+ gem.add_development_dependency "rspec"
20
+
21
+ gem.add_runtime_dependency "redcarpet"
22
+ gem.add_runtime_dependency "pygments.rb"
23
+ gem.add_runtime_dependency "gemoji"
24
+ end
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: velvet_rope
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Sean Gaffney
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: redcarpet
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: pygments.rb
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: gemoji
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: VelvetRope is a renderer to complement and enhance Redcarpet's default
79
+ HTML renderer. It adds support for emoji and syntax-highlighting.
80
+ email:
81
+ - sean@seangaffney.cc
82
+ executables: []
83
+ extensions: []
84
+ extra_rdoc_files: []
85
+ files:
86
+ - .gitignore
87
+ - .rspec
88
+ - CHANGELOG
89
+ - Gemfile
90
+ - LICENSE.txt
91
+ - README.md
92
+ - Rakefile
93
+ - lib/velvet_rope.rb
94
+ - spec/spec_helper.rb
95
+ - spec/velvet_rope_spec.rb
96
+ - velvet_rope.gemspec
97
+ homepage: http://github.com/seangaffney/velvet_rope
98
+ licenses: []
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ none: false
105
+ requirements:
106
+ - - ! '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ! '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 1.8.24
118
+ signing_key:
119
+ specification_version: 3
120
+ summary: Provides out-of-the-box syntax-highlighting and emoji support for the Redcarpet
121
+ markdown library.
122
+ test_files:
123
+ - spec/spec_helper.rb
124
+ - spec/velvet_rope_spec.rb