has_html_pipeline 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
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,2 @@
1
+ --color
2
+ --format progress
data/.travis.yml ADDED
@@ -0,0 +1,15 @@
1
+ language: ruby
2
+
3
+ jdk: openjdk7
4
+
5
+ env:
6
+ - JRUBY_OPTS="-Xcext.enabled=true"
7
+
8
+ rvm:
9
+ - 1.8.7
10
+ - ree
11
+ - 1.9.3
12
+ - 1.9.2
13
+ - ruby-head
14
+ - jruby-19mode
15
+ - jruby-head
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'html-pipeline-no-charlock'
4
+
5
+ # Specify your gem's dependencies in has_html_pipeline.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Ian Yang
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,48 @@
1
+ # HasHtmlPipeline
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add following lines to your application's Gemfile:
8
+
9
+ gem 'html-pipeline'
10
+ # or
11
+ # gem 'html-pipeline-no-charlock'
12
+ gem 'has_html_pipeline'
13
+
14
+ Gem `html-pipeline` must be added manually since it has too many unnecessary
15
+ dependencies, so you can choose to include `html-pipeline-no-charlock`.
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install html-pipeline # or html-pipeline-no-charlock
24
+ $ gem install has_html_pipeline
25
+
26
+ ## Usage
27
+
28
+ HasHtmlPipeline.register_html_pipeline(:markdown, [HTML::Pipeline::MarkdownFilter])
29
+
30
+ class User
31
+ extend HasHtmlPipeline
32
+
33
+ attr_accessor :about
34
+
35
+ has_html_pipeline :about, :markdown
36
+ end
37
+
38
+ u = User.new
39
+ u.about = '# Markdown #'
40
+ u.about_html # => '<h1>Markdown</h1>'
41
+
42
+ ## Contributing
43
+
44
+ 1. Fork it
45
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
46
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
47
+ 4. Push to the branch (`git push origin my-new-feature`)
48
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'has_html_pipeline/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "has_html_pipeline"
8
+ gem.version = HasHtmlPipeline::VERSION
9
+ gem.authors = ["Ian Yang"]
10
+ gem.email = ["me@iany.me"]
11
+ gem.description = %q{Ease using html-pipeline to convert an object attribute to HTML}
12
+ gem.summary = %q{Add a "#{attr}_html" method to apply the pre-registered html pipelines on attr getter method.}
13
+ gem.homepage = "https://github.com/doitian/has_html_pipeline"
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_development_dependency 'rake'
21
+ gem.add_development_dependency 'rspec'
22
+ end
@@ -0,0 +1,47 @@
1
+ require 'html/pipeline'
2
+
3
+ # Usage:
4
+ #
5
+ # HasHtmlPipeline.register_html_pipeline(:markdown, [HTML::Pipeline::MarkdownFilter])
6
+ #
7
+ # class User
8
+ # extend HasHtmlPipeline
9
+ #
10
+ # attr_accessor :about
11
+ #
12
+ # has_html_pipeline :about, :markdown
13
+ # end
14
+ #
15
+ # u = User.new
16
+ # u.about = '# Markdown #'
17
+ # u.about_html # => '<h1>Markdown</h1>'
18
+ #
19
+ module HasHtmlPipeline
20
+ class << self
21
+ # for `include HasHtmlPipeline`
22
+ def included(klass)
23
+ klass.extend(self)
24
+ end
25
+
26
+ def registered_html_pipelines
27
+ @registered_html_pipelines ||= {}
28
+ end
29
+
30
+ def register_html_pipeline(name, filters, context = {})
31
+ registered_html_pipelines[name.to_sym] = HTML::Pipeline.new(filters, context)
32
+ end
33
+
34
+ alias_method :register, :register_html_pipeline
35
+
36
+ def configure
37
+ yield self
38
+ end
39
+ end
40
+
41
+ def has_html_pipeline(field, pipeline_name)
42
+ define_method "#{field}_html" do
43
+ pipeline = ::HasHtmlPipeline.registered_html_pipelines[pipeline_name.to_sym]
44
+ pipeline.call(send(field))[:output].to_s
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,3 @@
1
+ module HasHtmlPipeline
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,38 @@
1
+ require 'has_html_pipeline'
2
+
3
+ describe HasHtmlPipeline do
4
+ context 'when a markdown pipeline has been registered' do
5
+ before do
6
+ HasHtmlPipeline.register_html_pipeline :test, [HTML::Pipeline::MarkdownFilter]
7
+ end
8
+
9
+ context 'User has field about and has the markdown pipeline on about' do
10
+ let(:klass) {
11
+ Class.new do
12
+ extend HasHtmlPipeline
13
+ attr_accessor :about
14
+ has_html_pipeline :about, :test
15
+ end
16
+ }
17
+ let(:user) { klass.new }
18
+
19
+ context 'when assign about with markdown' do
20
+ before do
21
+ user.about = <<-MD
22
+ # Title #
23
+
24
+ - list item 1
25
+ - list item 2
26
+ MD
27
+ end
28
+
29
+ subject { user.about_html }
30
+
31
+ it { should include('<h1>Title</h1>') }
32
+ it { should include('<li>list item 1</li>') }
33
+ it { should include('<li>list item 2</li>') }
34
+ end
35
+ end
36
+ end
37
+ end
38
+
@@ -0,0 +1,17 @@
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
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
+ RSpec.configure do |config|
8
+ config.treat_symbols_as_metadata_keys_with_true_values = true
9
+ config.run_all_when_everything_filtered = true
10
+ config.filter_run :focus
11
+
12
+ # Run specs in random order to surface order dependencies. If you find an
13
+ # order dependency and want to debug it, you can fix the order by providing
14
+ # the seed, which is printed after each run.
15
+ # --seed 1234
16
+ config.order = 'random'
17
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: has_html_pipeline
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ian Yang
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: rake
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: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
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
+ description: Ease using html-pipeline to convert an object attribute to HTML
47
+ email:
48
+ - me@iany.me
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - .rspec
55
+ - .travis.yml
56
+ - Gemfile
57
+ - LICENSE.txt
58
+ - README.md
59
+ - Rakefile
60
+ - has_html_pipeline.gemspec
61
+ - lib/has_html_pipeline.rb
62
+ - lib/has_html_pipeline/version.rb
63
+ - spec/lib/has_html_pipeline_spec.rb
64
+ - spec/spec_helper.rb
65
+ homepage: https://github.com/doitian/has_html_pipeline
66
+ licenses: []
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ segments:
78
+ - 0
79
+ hash: -4008131752445651120
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ segments:
87
+ - 0
88
+ hash: -4008131752445651120
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 1.8.23
92
+ signing_key:
93
+ specification_version: 3
94
+ summary: Add a "#{attr}_html" method to apply the pre-registered html pipelines on
95
+ attr getter method.
96
+ test_files:
97
+ - spec/lib/has_html_pipeline_spec.rb
98
+ - spec/spec_helper.rb