mongoid_markdown_extension 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0ec0073ca5dd466ba2075412834342b224ea4c28
4
+ data.tar.gz: c48aab24084b546fb27fcb448c1abd94790d3777
5
+ SHA512:
6
+ metadata.gz: 7f505fe915e92f7ba6346995591d57dce320b08e5421e85ce2e1e07f7f29e4d8abaff58e0751fdb2441cb5db2bd083070d79444c7a523ac52f47ad3460d9b74d
7
+ data.tar.gz: 69cc619d28479508754916cca970f1c1bd1c7053e92521a517b0bfc8f3fa8fd1373f2b6b051f40527aedc724491fac372b3da0f7ddb53f5a184694371333779f
@@ -0,0 +1,22 @@
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
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ cache: bundler
3
+ script: 'bundle exec rake'
4
+
5
+ notifications:
6
+ email:
7
+ recipients:
8
+ - tomas.celizna@gmail.com
9
+ on_failure: change
10
+ on_success: never
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mongoid_markdown_extension.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Tomas Celizna
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,68 @@
1
+ # Mongoid Markdown Extension
2
+
3
+ [![Build Status](https://travis-ci.org/tomasc/mongoid_markdown_extension.svg)](https://travis-ci.org/tomasc/mongoid_markdown_extension) [![Coverage Status](https://img.shields.io/coveralls/tomasc/mongoid_markdown_extension.svg)](https://coveralls.io/r/tomasc/mongoid_markdown_extension)
4
+
5
+ [Mongoid](https://github.com/mongoid/mongoid) field extension that returns an object with `to_html` method returning the content converted from Markdown syntax to html. The Markdown conversion is done using the [Redcarpet](https://github.com/vmg/redcarpet) library.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'mongoid_markdown_extension'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install mongoid_markdown_extension
20
+
21
+ ## Configuration
22
+
23
+ The defaults are as follows:
24
+
25
+ ```Ruby
26
+ extensions = {
27
+ autolink: true
28
+ footnotes: true
29
+ highlight: true
30
+ space_after_headers: true
31
+ strikethrough: true
32
+ superscript: true
33
+ }
34
+
35
+ render_options = {}
36
+ ```
37
+
38
+ These can be overwritten with an initializer, for example `config/initializers/mongoid_markdown.rb`:
39
+
40
+ ```Ruby
41
+ MongoidMarkdownExtension::Markdown.configure do |c|
42
+ c.extensions = { autolink: true }
43
+ c.render_options = { filter_html: true }
44
+ end
45
+ ```
46
+
47
+ See [Redcarpet documentation](https://github.com/vmg/redcarpet) for available extensions and render options.
48
+
49
+ ## Usage
50
+
51
+ Add to a Mongoid model:
52
+
53
+ class MyModel
54
+ include Mongoid::Document
55
+ field :text, type: MongoidMarkdownExtension::Markdown
56
+ end
57
+
58
+ Use it in a view:
59
+
60
+ = my_model.text.to_html
61
+
62
+ ## Contributing
63
+
64
+ 1. Fork it ( https://github.com/tomasc/mongoid_markdown_extension/fork )
65
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
66
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
67
+ 4. Push to the branch (`git push origin my-new-feature`)
68
+ 5. Create a new Pull Request
@@ -0,0 +1,9 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << 'test'
6
+ t.pattern = 'test/*/*_test.rb'
7
+ end
8
+
9
+ task :default => :test
@@ -0,0 +1,2 @@
1
+ require "mongoid_markdown_extension/markdown"
2
+ require "mongoid_markdown_extension/version"
@@ -0,0 +1,88 @@
1
+ require 'redcarpet'
2
+
3
+ module MongoidMarkdownExtension
4
+ class Markdown < String
5
+
6
+ def initialize str
7
+ super str.to_s
8
+ @str = str.to_s
9
+ end
10
+
11
+ def to_s
12
+ @str
13
+ end
14
+
15
+ def to_html
16
+ markdown_renderer.render(@str).html_safe
17
+ end
18
+
19
+ def mongoize
20
+ @str
21
+ end
22
+
23
+ private # =============================================================
24
+
25
+ def markdown_renderer
26
+ Redcarpet::Markdown.new(
27
+ Redcarpet::Render::HTML.new(self.class.configuration.render_options),
28
+ self.class.configuration.extensions
29
+ )
30
+ end
31
+
32
+ # ---------------------------------------------------------------------
33
+
34
+ class << self
35
+
36
+ attr_accessor :configuration
37
+
38
+ def configure
39
+ @configuration ||= Configuration.new
40
+ yield @configuration
41
+ end
42
+
43
+ def configuration
44
+ @configuration ||= Configuration.new
45
+ end
46
+
47
+ def demongoize value
48
+ Markdown.new(value)
49
+ end
50
+
51
+ def mongoize value
52
+ case value
53
+ when Markdown then value.mongoize
54
+ else value
55
+ end
56
+ end
57
+
58
+ def evolve value
59
+ case value
60
+ when Markdown then value.mongoize
61
+ else value
62
+ end
63
+ end
64
+
65
+ end
66
+ end
67
+
68
+ # ---------------------------------------------------------------------
69
+
70
+ class Configuration
71
+ attr_accessor :extensions
72
+ attr_accessor :render_options
73
+
74
+ def initialize
75
+ @extensions = {
76
+ autolink: true,
77
+ footnotes: true,
78
+ highlight: true,
79
+ space_after_headers: true,
80
+ strikethrough: true,
81
+ superscript: true
82
+ }
83
+ @render_options = {}
84
+ end
85
+ end
86
+
87
+ # ---------------------------------------------------------------------
88
+ end
@@ -0,0 +1,3 @@
1
+ module MongoidMarkdownExtension
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mongoid_markdown_extension/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mongoid_markdown_extension"
8
+ spec.version = MongoidMarkdownExtension::VERSION
9
+ spec.authors = ["Tomas Celizna"]
10
+ spec.email = ["tomas.celizna@gmail.com"]
11
+ spec.description = %q{Custom field type for Mongoid that handles Markdown conversion via Redcarpet gem.}
12
+ spec.summary = %q{Custom field type for Mongoid that handles Markdown conversion via Redcarpet gem.}
13
+ spec.homepage = "https://github.com/tomasc/mongoid_markdown_extension"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "redcarpet", ">= 3.1.2"
22
+ spec.add_dependency "mongoid", ">= 4.0"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.6"
25
+ spec.add_development_dependency "coveralls"
26
+ spec.add_development_dependency "rake"
27
+ end
@@ -0,0 +1 @@
1
+ service_name: travis-ci
@@ -0,0 +1,88 @@
1
+ require 'test_helper'
2
+
3
+ # ---------------------------------------------------------------------
4
+
5
+ class MongoidMarkdownExtensionTest
6
+ include Mongoid::Document
7
+ field :body, type: MongoidMarkdownExtension::Markdown
8
+ end
9
+
10
+ # ---------------------------------------------------------------------
11
+
12
+ module MongoidMarkdownExtension
13
+ describe Markdown do
14
+
15
+ let(:string) { 'some text with _italic_' }
16
+ subject { MongoidMarkdownExtension::Markdown.new(string) }
17
+
18
+ describe 'configuration' do
19
+ describe 'setup block' do
20
+ it 'yields self' do
21
+ MongoidMarkdownExtension::Markdown.configure do |config|
22
+ config.must_be_kind_of Configuration
23
+ end
24
+ end
25
+ it 'returns default values' do
26
+ MongoidMarkdownExtension::Markdown.configuration.extensions.must_equal({
27
+ autolink: true,
28
+ footnotes: true,
29
+ highlight: true,
30
+ space_after_headers: true,
31
+ strikethrough: true,
32
+ superscript: true
33
+ })
34
+ MongoidMarkdownExtension::Markdown.configuration.render_options.must_equal({})
35
+ end
36
+ end
37
+ end
38
+
39
+ # ---------------------------------------------------------------------
40
+
41
+ describe '#to_s' do
42
+ it 'returns the original value' do
43
+ subject.to_s.must_equal string
44
+ end
45
+ end
46
+
47
+ describe '#to_html' do
48
+ it 'survives nil' do
49
+ MongoidMarkdownExtension::Markdown.new(nil).to_html.must_equal ''
50
+ end
51
+ it 'converts the string to html' do
52
+ subject.to_html.must_equal Redcarpet::Markdown.new(Redcarpet::Render::HTML).render(string)
53
+ end
54
+ end
55
+
56
+ describe '#mongoize' do
57
+ it 'returns string' do
58
+ subject.mongoize.must_equal string
59
+ end
60
+ end
61
+
62
+ # ---------------------------------------------------------------------
63
+
64
+ describe '.mongoize' do
65
+ describe 'when passed a string' do
66
+ it 'returns it back' do
67
+ MongoidMarkdownExtension::Markdown.mongoize(string).must_equal string
68
+ end
69
+ end
70
+ describe 'when passed markdown object' do
71
+ it 'returns its string' do
72
+ MongoidMarkdownExtension::Markdown.mongoize(subject).must_be_kind_of String
73
+ end
74
+ end
75
+ end
76
+
77
+ describe '.demongoize' do
78
+ it 'does not change the value' do
79
+ MongoidMarkdownExtension::Markdown.demongoize(string).must_equal string
80
+ end
81
+
82
+ it 'returns markdown object' do
83
+ MongoidMarkdownExtension::Markdown.demongoize(string).must_be_kind_of MongoidMarkdownExtension::Markdown
84
+ end
85
+ end
86
+
87
+ end
88
+ end
@@ -0,0 +1,9 @@
1
+ require 'bundler/setup'
2
+ require 'mongoid'
3
+ require 'mongoid_markdown_extension'
4
+ require 'minitest'
5
+ require 'minitest/autorun'
6
+ require 'minitest/spec'
7
+ require 'coveralls'
8
+
9
+ Coveralls.wear!
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mongoid_markdown_extension
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Tomas Celizna
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: redcarpet
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 3.1.2
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 3.1.2
27
+ - !ruby/object:Gem::Dependency
28
+ name: mongoid
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '4.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '4.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.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: coveralls
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: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Custom field type for Mongoid that handles Markdown conversion via Redcarpet
84
+ gem.
85
+ email:
86
+ - tomas.celizna@gmail.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - .gitignore
92
+ - .travis.yml
93
+ - Gemfile
94
+ - LICENSE
95
+ - README.md
96
+ - Rakefile
97
+ - lib/mongoid_markdown_extension.rb
98
+ - lib/mongoid_markdown_extension/markdown.rb
99
+ - lib/mongoid_markdown_extension/version.rb
100
+ - mongoid_markdown_extension.gemspec
101
+ - test/.coveralls.yml
102
+ - test/mongoid_markdown_extension/markdown_test.rb
103
+ - test/test_helper.rb
104
+ homepage: https://github.com/tomasc/mongoid_markdown_extension
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.1.10
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: Custom field type for Mongoid that handles Markdown conversion via Redcarpet
128
+ gem.
129
+ test_files:
130
+ - test/.coveralls.yml
131
+ - test/mongoid_markdown_extension/markdown_test.rb
132
+ - test/test_helper.rb
133
+ has_rdoc: