html_pipeline_rails 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 001523be3aba2cbb410842e4fa47a04fb16ea34c
4
+ data.tar.gz: 1e02571da32c0e5e54498d6862c42b1962252af0
5
+ SHA512:
6
+ metadata.gz: 540936f9d7a33b41ac0b6c609cbe7ea9ed8ef6e30f4d3cde92170a3fdf0bf5ea619c96bc2b717a41f534dfd59213c7abef176e3f0375ac8ee093295e4e68311a
7
+ data.tar.gz: 2c4ba2973a8a38da9d5a74362b7d69091d11f3864f7c0abd77f9d6353c512f6af37b5b545a8df7471a8565ff79d5277a64ed063a27bacc58c3cc85c652821da5
@@ -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,2 @@
1
+ --color
2
+ --format progress
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ script: bundle exec rspec
3
+ rvm:
4
+ - 2.1.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in html_pipeline_rails.gemspec
4
+ gemspec
@@ -0,0 +1,5 @@
1
+ guard :rspec do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/}) { 'spec' }
4
+ watch('spec/spec_helper.rb') { 'spec' }
5
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Aidan Feldman
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,45 @@
1
+ # HTML::Pipeline for Rails [![Build Status](https://travis-ci.org/afeld/html_pipeline_rails.png?branch=master)](https://travis-ci.org/afeld/html_pipeline_rails)
2
+
3
+ Adds support for rendering views via [HTML::Pipeline](https://github.com/jch/html-pipeline) in Rails. [GitHub Flavored Markdown](https://help.github.com/articles/github-flavored-markdown) in your Rails app!
4
+
5
+ ## Installation
6
+
7
+ Add this line to your Gemfile:
8
+
9
+ ```ruby
10
+ gem 'html_pipeline_rails'
11
+ ```
12
+
13
+ and then run:
14
+
15
+ $ bundle
16
+
17
+ All views ending in `.md` will then be rendered as HTML. Otherwise, they act the same as normal `.html.erb` files. Cool, eh?
18
+
19
+ ## Customization
20
+
21
+ By default, `.md` views will run through ERB, and then the `MarkdownFilter` pipeline. You can customize the render pipeline like so:
22
+
23
+ ```ruby
24
+ # config/initializers/html_pipeline.rb
25
+ HtmlPipelineRails.config do |c|
26
+ c.pipeline = HTML::Pipeline.new([
27
+ HTML::Pipeline::MarkdownFilter,
28
+ HTML::Pipeline::MentionFilter
29
+ ])
30
+ end
31
+ ```
32
+
33
+ In this case, `@mention`s will now be converted to links. See [the HTML::Pipeline documentation](https://github.com/jch/html-pipeline#usage) to learn about the different options.
34
+
35
+ ## Contributing
36
+
37
+ Run tests with:
38
+
39
+ ```bash
40
+ bundle
41
+ # then
42
+ bundle exec rspec
43
+ # or
44
+ bundle exec guard
45
+ ```
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'html_pipeline_rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "html_pipeline_rails"
8
+ spec.version = HtmlPipelineRails::VERSION
9
+ spec.authors = ["Aidan Feldman"]
10
+ spec.email = ["aidan.feldman@gmail.com"]
11
+ spec.summary = %q{Render Markdown via HTML::Pipeline in Rails.}
12
+ spec.homepage = "https://github.com/afeld/html_pipeline_rails/"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "github-markdown"
21
+ spec.add_dependency "html-pipeline"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.5"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "actionpack", ">= 3.0"
26
+ spec.add_development_dependency "rspec", "~> 2.14"
27
+
28
+ spec.add_development_dependency "guard"
29
+ spec.add_development_dependency "guard-rspec"
30
+ end
@@ -0,0 +1,18 @@
1
+ require 'html_pipeline_rails/configuration'
2
+ require 'html_pipeline_rails/handler'
3
+ require 'html_pipeline_rails/version'
4
+
5
+ require 'active_support/core_ext/module/attribute_accessors'
6
+
7
+ module HtmlPipelineRails
8
+ mattr_accessor :configuration
9
+ self.configuration = Configuration.new
10
+
11
+ def self.config
12
+ yield self.configuration
13
+ end
14
+ end
15
+
16
+ ActionView::Template.register_template_handler(:md, HtmlPipelineRails::Handler.new)
17
+ ActionView::Template.register_template_handler(:mdown, HtmlPipelineRails::Handler.new)
18
+ ActionView::Template.register_template_handler(:markdown, HtmlPipelineRails::Handler.new)
@@ -0,0 +1,15 @@
1
+ module HtmlPipelineRails
2
+ class Configuration
3
+ attr_accessor :pipeline
4
+
5
+ def initialize
6
+ self.reset!
7
+ end
8
+
9
+ def reset!
10
+ self.pipeline = HTML::Pipeline.new([
11
+ HTML::Pipeline::MarkdownFilter
12
+ ])
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,24 @@
1
+ require 'html/pipeline'
2
+
3
+ module HtmlPipelineRails
4
+ class Handler
5
+ def default_format
6
+ :html
7
+ end
8
+
9
+ def call(template)
10
+ compiled_source = self.class.erb.call(template)
11
+
12
+ <<-END
13
+ pipeline = HtmlPipelineRails.configuration.pipeline
14
+ result = pipeline.call(begin;#{compiled_source};end)
15
+ result[:output].to_s
16
+ END
17
+ end
18
+
19
+ # via http://stackoverflow.com/a/10131299/358804
20
+ def self.erb
21
+ @erb ||= ActionView::Template.registered_template_handler(:erb)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,3 @@
1
+ module HtmlPipelineRails
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ describe HtmlPipelineRails::Configuration do
4
+ describe '#reset' do
5
+ let(:config) { HtmlPipelineRails::Configuration.new }
6
+
7
+ it "sets the pipeline to the default" do
8
+ config.pipeline = HTML::Pipeline.new([
9
+ HTML::Pipeline::MarkdownFilter,
10
+ HTML::Pipeline::MentionFilter
11
+ ])
12
+ config.reset!
13
+ expect(config.pipeline.filters).to eq([HTML::Pipeline::MarkdownFilter])
14
+ end
15
+ end
16
+ end
@@ -0,0 +1 @@
1
+ # Fake Heading
@@ -0,0 +1 @@
1
+ # A Heading
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe HtmlPipelineRails do
4
+ describe '.config' do
5
+ it "runs the config block" do
6
+ block_run = false
7
+ HtmlPipelineRails.config do |c|
8
+ block_run = true
9
+ end
10
+ expect(block_run).to be_true
11
+ end
12
+
13
+ it "defaults to include the MarkdownFilter" do
14
+ HtmlPipelineRails.config do |c|
15
+ pipeline = c.pipeline
16
+ expect(pipeline).to be_an(HTML::Pipeline)
17
+ expect(pipeline.filters).to eq([HTML::Pipeline::MarkdownFilter])
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+
3
+ describe "markdown views" do
4
+ before do
5
+ setup_view_instance
6
+ end
7
+
8
+ it "inline rendering" do
9
+ template = '# A Heading'
10
+ result = @view.render(inline: template, type: :md)
11
+ expect(result).to eq('<h1>A Heading</h1>')
12
+ end
13
+
14
+ it "doesn't affect normal HTML rendering" do
15
+ template = '# A Heading'
16
+ result = @view.render(inline: template)
17
+ expect(result).to eq(template)
18
+ end
19
+
20
+ it "renders external templates" do
21
+ result = @view.render('simple_md')
22
+ expect(result).to eq("<h1>A Heading</h1>")
23
+ end
24
+
25
+ it "doesn't affect normal external HTML templates" do
26
+ result = @view.render('fake_md')
27
+ expect(result).to eq("# Fake Heading\n")
28
+ end
29
+
30
+ it "interprets ERB" do
31
+ template = '<%= 1 + 1 %>'
32
+ result = @view.render(inline: template, type: :md)
33
+ # not sure why it gets wrapped...
34
+ expect(result).to eq('<p>2</p>')
35
+ end
36
+
37
+ it "uses the configured pipeline" do
38
+ HtmlPipelineRails.config do |c|
39
+ c.pipeline = HTML::Pipeline.new([
40
+ HTML::Pipeline::MarkdownFilter,
41
+ HTML::Pipeline::MentionFilter
42
+ ])
43
+ end
44
+
45
+ template = '@afeld'
46
+ result = @view.render(inline: template, type: :md)
47
+ expect(result).to eq('<p><a href="/afeld" class="user-mention">@afeld</a></p>')
48
+ end
49
+ end
@@ -0,0 +1,33 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # Require this file using `require "spec_helper"` to ensure that it is only
4
+ # loaded once.
5
+
6
+ require 'action_view'
7
+ require_relative '../lib/html_pipeline_rails'
8
+
9
+
10
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
11
+ RSpec.configure do |config|
12
+ config.treat_symbols_as_metadata_keys_with_true_values = true
13
+ config.run_all_when_everything_filtered = true
14
+ config.filter_run :focus
15
+
16
+ # Run specs in random order to surface order dependencies. If you find an
17
+ # order dependency and want to debug it, you can fix the order by providing
18
+ # the seed, which is printed after each run.
19
+ # --seed 1234
20
+ config.order = 'random'
21
+
22
+ config.before do
23
+ HtmlPipelineRails.config do |c|
24
+ c.reset!
25
+ end
26
+ end
27
+ end
28
+
29
+
30
+ def setup_view_instance
31
+ @view = ActionView::Base.new
32
+ @view.view_paths << File.join(File.dirname(__FILE__), 'fixtures', 'templates')
33
+ end
metadata ADDED
@@ -0,0 +1,181 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: html_pipeline_rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Aidan Feldman
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: github-markdown
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: html-pipeline
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: actionpack
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: '2.14'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: '2.14'
97
+ - !ruby/object:Gem::Dependency
98
+ name: guard
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: guard-rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description:
126
+ email:
127
+ - aidan.feldman@gmail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - .gitignore
133
+ - .rspec
134
+ - .travis.yml
135
+ - Gemfile
136
+ - Guardfile
137
+ - LICENSE.txt
138
+ - README.md
139
+ - Rakefile
140
+ - html_pipeline_rails.gemspec
141
+ - lib/html_pipeline_rails.rb
142
+ - lib/html_pipeline_rails/configuration.rb
143
+ - lib/html_pipeline_rails/handler.rb
144
+ - lib/html_pipeline_rails/version.rb
145
+ - spec/configuration_spec.rb
146
+ - spec/fixtures/templates/_fake_md.html
147
+ - spec/fixtures/templates/_simple_md.html.md
148
+ - spec/html_pipeline_rails_spec.rb
149
+ - spec/markdown_spec.rb
150
+ - spec/spec_helper.rb
151
+ homepage: https://github.com/afeld/html_pipeline_rails/
152
+ licenses:
153
+ - MIT
154
+ metadata: {}
155
+ post_install_message:
156
+ rdoc_options: []
157
+ require_paths:
158
+ - lib
159
+ required_ruby_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - '>='
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ required_rubygems_version: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - '>='
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
169
+ requirements: []
170
+ rubyforge_project:
171
+ rubygems_version: 2.2.1
172
+ signing_key:
173
+ specification_version: 4
174
+ summary: Render Markdown via HTML::Pipeline in Rails.
175
+ test_files:
176
+ - spec/configuration_spec.rb
177
+ - spec/fixtures/templates/_fake_md.html
178
+ - spec/fixtures/templates/_simple_md.html.md
179
+ - spec/html_pipeline_rails_spec.rb
180
+ - spec/markdown_spec.rb
181
+ - spec/spec_helper.rb