forem-kramdown 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
@@ -0,0 +1 @@
1
+ 1.9.3@forem-kramdown
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
5
+ - 1.9.3
6
+ - jruby-19mode
7
+ - rbx-19mode
8
+ env:
9
+ - CI=true JRUBY_OPTS=--1.9 RBXOPT=-X19
10
+ script: "./test/ci/ci_runner.sh"
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ platform :mri_19 do
6
+ gem "cane", "~> 2.5.0"
7
+ gem "coveralls", "~> 0.5.5"
8
+ gem "simplecov", "~> 0.7.1"
9
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Phil Cohen
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.
@@ -0,0 +1,74 @@
1
+ # forem-kramdown
2
+
3
+ [![Build Status](https://travis-ci.org/phlipper/forem-kramdown.png?branch=master)](https://travis-ci.org/phlipper/forem-kramdown)
4
+
5
+
6
+ ## Description
7
+
8
+ Provides [Kramdown](http://kramdown.rubyforge.org/) markup (with syntax highlighting by [CodeRay](http://coderay.rubychan.de/)) for [Forem](https://github.com/radar/forem) posts.
9
+
10
+ This gem is based on [forem-redcarpet](https://github.com/radar/forem-redcarpet).
11
+
12
+
13
+ ## Requirements
14
+
15
+ This gem requires Rails 3.1+ and Forem 1.0.0.beta1.
16
+
17
+ This gem has been tested against the following Ruby versions:
18
+
19
+ * 1.8.7
20
+ * 1.9.2
21
+ * 1.9.3
22
+ * JRuby
23
+ * Rubinius
24
+
25
+
26
+ ## Installation
27
+
28
+ Add this line to your application's Gemfile:
29
+
30
+ ```ruby
31
+ gem "forem-kramdown"
32
+ ```
33
+
34
+ And then execute:
35
+
36
+ ```
37
+ $ bundle
38
+ ```
39
+
40
+ Or install it yourself as:
41
+
42
+ ```
43
+ $ gem install forem-kramdown
44
+ ```
45
+
46
+
47
+ ## Usage
48
+
49
+ Specify this gem as a dependency of an application that also contains Forem:
50
+
51
+ ```ruby
52
+ gem "forem", git: "git://github.com/radar/forem"
53
+ gem "forem-kramdown"
54
+ ```
55
+
56
+ The code will do the rest!
57
+
58
+
59
+ ## Contributing
60
+
61
+ 1. [Fork it](https://github.com/phlipper/forem-kramdown/fork_select)
62
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
63
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
64
+ 4. Push to the branch (`git push origin my-new-feature`)
65
+ 5. [Create a Pull Request](hhttps://github.com/phlipper/forem-kramdown/pull/new)
66
+
67
+
68
+ ## License
69
+
70
+ **sugar-rails**
71
+
72
+ * Freely distributable and licensed under the [MIT license](http://phlipper.mit-license.org/2012/license.html).
73
+ * Copyright (c) 2012 Phil Cohen (github@phlippers.net) [![endorse](http://api.coderwall.com/phlipper/endorsecount.png)](http://coderwall.com/phlipper)
74
+ * http://phlippers.net/
@@ -0,0 +1,12 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require "rake/testtask"
4
+
5
+ task :default => :test
6
+
7
+ Rake::TestTask.new(:test) do |t|
8
+ t.libs << "lib"
9
+ t.libs << "test"
10
+ t.pattern = "test/**/*_test.rb"
11
+ t.verbose = false
12
+ end
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "forem-kramdown/version"
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "forem-kramdown"
8
+ gem.version = Forem::Kramdown::VERSION
9
+ gem.authors = ["Phil Cohen"]
10
+ gem.email = ["github@phlippers.net"]
11
+ gem.description = "Provides Kramdown markup (with syntax highlighting by CodeRay) for Forem posts"
12
+ gem.summary = "Provides Kramdown markup (with syntax highlighting by CodeRay) for Forem posts"
13
+ gem.homepage = "http://phlippers.net/forem-kramdown"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency "activesupport", ">= 3.1.0"
21
+ gem.add_dependency "coderay", "~> 1.0.8"
22
+ gem.add_dependency "kramdown", "~> 0.14.1"
23
+ gem.add_dependency "nokogiri", "~> 1.5.6"
24
+
25
+ gem.add_development_dependency "minitest", "~> 4.3.0"
26
+ gem.add_development_dependency "rake", "~> 10.0.0"
27
+ end
@@ -0,0 +1,5 @@
1
+ require "forem/formatters/kramdown"
2
+
3
+ if Forem.respond_to?(:formatter=)
4
+ Forem.formatter = Forem::Formatters::Kramdown
5
+ end
@@ -0,0 +1,5 @@
1
+ module Forem
2
+ module Kramdown
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,32 @@
1
+ require "active_support/core_ext/string"
2
+ require "coderay"
3
+ require "kramdown"
4
+ require "nokogiri"
5
+
6
+ module Forem
7
+ module Formatters
8
+
9
+ # Public: Various methods useful for formatting text with Kramdown.
10
+ class Kramdown
11
+ def self.format(text)
12
+ renderer = ::Kramdown::Document.new(text.to_s)
13
+ syntax_highlight(renderer.to_html).html_safe
14
+ end
15
+
16
+ def self.blockquote(text)
17
+ text.to_s.split("\n").map { |line| "> #{line}" }.join("\n")
18
+ end
19
+
20
+ def self.syntax_highlight(html)
21
+ doc = ::Nokogiri::HTML::DocumentFragment.parse(html.to_s)
22
+ doc.css("pre code[@class]").each do |code|
23
+ line_numbers = { :line_numbers => :inline }
24
+ language = code[:class].to_sym
25
+ syntax = CodeRay.scan(code.text.rstrip, language).div(line_numbers)
26
+ code.replace %(<div class="forem_highlight">#{syntax}</div>)
27
+ end
28
+ doc.to_s.html_safe
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,8 @@
1
+ engine=$(ruby -e 'puts defined?(RUBY_ENGINE) ? RUBY_ENGINE : ""')
2
+
3
+ case $engine in
4
+ "ruby" )
5
+ bundle exec rake test && bundle exec cane;;
6
+ * )
7
+ bundle exec rake test;;
8
+ esac
@@ -0,0 +1,45 @@
1
+ require "minitest_helper"
2
+
3
+ describe Forem::Formatters::Kramdown do
4
+ subject { Forem::Formatters::Kramdown }
5
+
6
+ it "exists" do
7
+ subject.new.must_be_kind_of Forem::Formatters::Kramdown
8
+ end
9
+
10
+ describe "self.format" do
11
+ let(:plain_text) { "this is not markdown" }
12
+ let(:plain_html) { "<p>this is not markdown</p>" }
13
+ let(:markdown_text) { "test *is* **markdown**" }
14
+ let(:markdown_html) { "<p>test <em>is</em> <strong>markdown</strong></p>" }
15
+
16
+ it { subject.format(plain_text).must_equal plain_html }
17
+ it { subject.format(markdown_text).must_equal markdown_html }
18
+ end
19
+
20
+ describe "self.blockquote" do
21
+ it { subject.blockquote("hello").must_equal "> hello" }
22
+ it { subject.blockquote("hello\nworld").must_equal "> hello\n> world" }
23
+ end
24
+
25
+ describe "self.syntax_highlight" do
26
+ let(:ruby_html) { %(<pre><code class="ruby">"hello world"</code></pre>) }
27
+
28
+ it { subject.syntax_highlight("hello").must_equal "hello" }
29
+ it {
30
+ subject.syntax_highlight(ruby_html).must_match(
31
+ %(<div class="forem_highlight">)
32
+ )
33
+ }
34
+ it {
35
+ subject.syntax_highlight(ruby_html).must_match(
36
+ %(<div class="CodeRay">)
37
+ )
38
+ }
39
+ it {
40
+ subject.syntax_highlight(ruby_html).must_match(
41
+ %(<span class="line-numbers"><a href="#n1" name="n1">1</a></span>)
42
+ )
43
+ }
44
+ end
45
+ end
@@ -0,0 +1,27 @@
1
+ if RUBY_VERSION > "1.9" && RUBY_ENGINE == "ruby"
2
+ require "simplecov"
3
+ require "coveralls"
4
+
5
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
6
+ SimpleCov::Formatter::HTMLFormatter,
7
+ Coveralls::SimpleCov::Formatter
8
+ ]
9
+
10
+ SimpleCov.start do
11
+ add_filter "test"
12
+ command_name "MiniTest"
13
+ end
14
+ end
15
+
16
+ require "minitest/autorun"
17
+ require "minitest/pride"
18
+
19
+ # Note: `Forem` must respond to `.formatter=` before the tests are run for
20
+ # SimpleCov to register the coverage. This avoids the need to bring along
21
+ # Forem and Rails with this library.
22
+ module Forem
23
+ def self.formatter=(formatter)
24
+ end
25
+ end
26
+
27
+ require File.expand_path("../../lib/forem-kramdown", __FILE__)
metadata ADDED
@@ -0,0 +1,166 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: forem-kramdown
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.0
6
+ platform: ruby
7
+ authors:
8
+ - Phil Cohen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-31 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ! '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 3.1.0
20
+ none: false
21
+ prerelease: false
22
+ name: activesupport
23
+ requirement: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ! '>='
26
+ - !ruby/object:Gem::Version
27
+ version: 3.1.0
28
+ none: false
29
+ type: :runtime
30
+ - !ruby/object:Gem::Dependency
31
+ version_requirements: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ~>
34
+ - !ruby/object:Gem::Version
35
+ version: 1.0.8
36
+ none: false
37
+ prerelease: false
38
+ name: coderay
39
+ requirement: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 1.0.8
44
+ none: false
45
+ type: :runtime
46
+ - !ruby/object:Gem::Dependency
47
+ version_requirements: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ~>
50
+ - !ruby/object:Gem::Version
51
+ version: 0.14.1
52
+ none: false
53
+ prerelease: false
54
+ name: kramdown
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ~>
58
+ - !ruby/object:Gem::Version
59
+ version: 0.14.1
60
+ none: false
61
+ type: :runtime
62
+ - !ruby/object:Gem::Dependency
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ~>
66
+ - !ruby/object:Gem::Version
67
+ version: 1.5.6
68
+ none: false
69
+ prerelease: false
70
+ name: nokogiri
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: 1.5.6
76
+ none: false
77
+ type: :runtime
78
+ - !ruby/object:Gem::Dependency
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ~>
82
+ - !ruby/object:Gem::Version
83
+ version: 4.3.0
84
+ none: false
85
+ prerelease: false
86
+ name: minitest
87
+ requirement: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ~>
90
+ - !ruby/object:Gem::Version
91
+ version: 4.3.0
92
+ none: false
93
+ type: :development
94
+ - !ruby/object:Gem::Dependency
95
+ version_requirements: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ~>
98
+ - !ruby/object:Gem::Version
99
+ version: 10.0.0
100
+ none: false
101
+ prerelease: false
102
+ name: rake
103
+ requirement: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ~>
106
+ - !ruby/object:Gem::Version
107
+ version: 10.0.0
108
+ none: false
109
+ type: :development
110
+ description: Provides Kramdown markup (with syntax highlighting by CodeRay) for Forem
111
+ posts
112
+ email:
113
+ - github@phlippers.net
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - .gitignore
119
+ - .ruby-version
120
+ - .travis.yml
121
+ - Gemfile
122
+ - LICENSE.txt
123
+ - README.md
124
+ - Rakefile
125
+ - forem-kramdown.gemspec
126
+ - lib/forem-kramdown.rb
127
+ - lib/forem-kramdown/version.rb
128
+ - lib/forem/formatters/kramdown.rb
129
+ - test/ci/ci_runner.sh
130
+ - test/forem_formatters_kramdown_test.rb
131
+ - test/minitest_helper.rb
132
+ homepage: http://phlippers.net/forem-kramdown
133
+ licenses: []
134
+ post_install_message:
135
+ rdoc_options: []
136
+ require_paths:
137
+ - lib
138
+ required_ruby_version: !ruby/object:Gem::Requirement
139
+ requirements:
140
+ - - ! '>='
141
+ - !ruby/object:Gem::Version
142
+ version: '0'
143
+ segments:
144
+ - 0
145
+ hash: 1465204160869020178
146
+ none: false
147
+ required_rubygems_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ! '>='
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ segments:
153
+ - 0
154
+ hash: 1465204160869020178
155
+ none: false
156
+ requirements: []
157
+ rubyforge_project:
158
+ rubygems_version: 1.8.24
159
+ signing_key:
160
+ specification_version: 3
161
+ summary: Provides Kramdown markup (with syntax highlighting by CodeRay) for Forem
162
+ posts
163
+ test_files:
164
+ - test/ci/ci_runner.sh
165
+ - test/forem_formatters_kramdown_test.rb
166
+ - test/minitest_helper.rb