mongoid_markdown 0.1.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/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mongoid_markdown.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,10 @@
1
+ guard 'rspec' do
2
+
3
+ # Run spec if spec changes
4
+ watch(%r{^spec/.+_spec\.rb$})
5
+
6
+ # Run all specs if anything changes
7
+ watch(%r{^lib/(.+)\.rb$}) { 'spec' }
8
+ watch('spec/spec_helper.rb') { 'spec' }
9
+ end
10
+
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Lasse Skindstad Ebert
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,55 @@
1
+ # mongoid_markdown
2
+
3
+ Makes it easy to handle a field in a mongoid document that contains markdown.
4
+
5
+ Creates an extra method `parsed_field_name` which will return the HTML markup of the markdown.
6
+
7
+ ## Installation
8
+
9
+ **Note: This is not published to RubyGems yet - waiting for their recovery**
10
+
11
+ **In the meantime use `gem 'mongoid_markdown', git: 'https://github.com/lasseebert/mongoid_markdown.git'`**
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ gem 'mongoid_markdown'
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install mongoid_markdown
24
+
25
+ ## Usage
26
+
27
+ * Include `MongoidMarkdown::Parser`
28
+ * Add field with `markdown` instead of the normal `field`
29
+ * Enjoy the `parsed_field_name` method
30
+
31
+ Example:
32
+ ```ruby
33
+ class Article
34
+ include Mongoid::Document
35
+ include MongoidMarkdown::Parser
36
+
37
+ field :header, type: String
38
+ markdown :content
39
+ end
40
+
41
+ article = Article.new header: 'Check out mongoid_markdown', content: "Wow\n\n* list\n* *items*"
42
+ article.parsed_content # => "<p>Wow</p>\n\n<ul>\n<li>list</li>\n<li><em>items</em></li>\n</ul>\n"
43
+ ```
44
+
45
+ ## Alternatives
46
+
47
+ [mongoid-markdown](https://github.com/kristianmandrup/mongoid-markdown), which takes a slightly different approach.
48
+
49
+ ## Contributing
50
+
51
+ 1. Fork it
52
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
53
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
54
+ 4. Push to the branch (`git push origin my-new-feature`)
55
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,33 @@
1
+ require 'mongoid_markdown/version'
2
+ require 'redcarpet'
3
+
4
+ module MongoidMarkdown
5
+ module Parser
6
+
7
+ def self.included(base)
8
+ base.class_eval do |klass|
9
+ extend ClassMethods
10
+ end
11
+ end
12
+
13
+ module ClassMethods
14
+ def markdown(field_name)
15
+ field field_name, type: String
16
+ define_method("parsed_#{field_name.to_s}") do
17
+ self.class.parse_markdown self.send(field_name)
18
+ end
19
+ end
20
+
21
+ def parse_markdown(markdown)
22
+ return nil if markdown.nil?
23
+ @@markdown_parser ||= Redcarpet::Markdown.new(
24
+ Redcarpet::Render::HTML,
25
+ autolink: true
26
+ )
27
+ @@markdown_parser.render(markdown).html_safe
28
+ end
29
+ end
30
+
31
+ end
32
+ end
33
+
@@ -0,0 +1,3 @@
1
+ module MongoidMarkdown
2
+ VERSION = "0.1.1"
3
+ 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 'mongoid_markdown/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "mongoid_markdown"
8
+ gem.version = MongoidMarkdown::VERSION
9
+ gem.authors = ["Lasse Skindstad Ebert"]
10
+ gem.email = ["lasseebert@gmail.com"]
11
+ gem.description = %q{Makes it easy to use markdown with mongoid}
12
+ gem.summary = %q{Makes it easy to use markdown with mongoid}
13
+ gem.homepage = ""
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 'redcarpet', '~> 2.2'
21
+ gem.add_dependency 'mongoid'
22
+
23
+ gem.add_development_dependency 'rspec', '~> 2.12'
24
+ gem.add_development_dependency 'guard-rspec', '~> 2.4'
25
+ gem.add_development_dependency 'rb-inotify', '~> 0.8.8'
26
+
27
+ end
@@ -0,0 +1,8 @@
1
+ require 'rspec'
2
+ require 'mongoid_markdown'
3
+ require 'mongoid'
4
+
5
+ RSpec.configure do |config|
6
+ config.color_enabled = true
7
+ config.formatter = 'documentation'
8
+ end
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+
3
+ class Article
4
+ include Mongoid::Document
5
+ include MongoidMarkdown::Parser
6
+
7
+ field :header, type: String
8
+ markdown :content
9
+ end
10
+
11
+ describe 'markdown' do
12
+ it 'can call parsed_ method' do
13
+ article = Article.new content: 'foo'
14
+ article.parsed_content.should == "<p>foo</p>\n"
15
+ end
16
+
17
+ describe 'parse_markdown' do
18
+ it 'passes markdown' do
19
+ markdown = <<-EOF.strip_heredoc
20
+ #This is a header
21
+
22
+ A paragraph with a small amount of text
23
+
24
+ * List with
25
+ * Three
26
+ * Items
27
+ EOF
28
+
29
+ expected = <<-EOF.strip_heredoc.html_safe
30
+ <h1>This is a header</h1>
31
+
32
+ <p>A paragraph with a small amount of text</p>
33
+
34
+ <ul>
35
+ <li>List with</li>
36
+ <li>Three</li>
37
+ <li>Items</li>
38
+ </ul>
39
+ EOF
40
+ html = Article.parse_markdown markdown
41
+ html.should == expected
42
+ end
43
+
44
+ it 'returns nil in nil input' do
45
+ Article.parse_markdown(nil).should be_nil
46
+ end
47
+ end
48
+ end
49
+
metadata ADDED
@@ -0,0 +1,144 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mongoid_markdown
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Lasse Skindstad Ebert
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-02 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: redcarpet
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '2.2'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '2.2'
30
+ - !ruby/object:Gem::Dependency
31
+ name: mongoid
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: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '2.12'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '2.12'
62
+ - !ruby/object:Gem::Dependency
63
+ name: guard-rspec
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '2.4'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '2.4'
78
+ - !ruby/object:Gem::Dependency
79
+ name: rb-inotify
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 0.8.8
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 0.8.8
94
+ description: Makes it easy to use markdown with mongoid
95
+ email:
96
+ - lasseebert@gmail.com
97
+ executables: []
98
+ extensions: []
99
+ extra_rdoc_files: []
100
+ files:
101
+ - .gitignore
102
+ - Gemfile
103
+ - Guardfile
104
+ - LICENSE.txt
105
+ - README.md
106
+ - Rakefile
107
+ - lib/mongoid_markdown.rb
108
+ - lib/mongoid_markdown/version.rb
109
+ - mongoid_markdown.gemspec
110
+ - spec/spec_helper.rb
111
+ - spec/unit/markdown_spec.rb
112
+ homepage: ''
113
+ licenses: []
114
+ post_install_message:
115
+ rdoc_options: []
116
+ require_paths:
117
+ - lib
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ none: false
120
+ requirements:
121
+ - - ! '>='
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ segments:
125
+ - 0
126
+ hash: 2325908448554059919
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ none: false
129
+ requirements:
130
+ - - ! '>='
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ segments:
134
+ - 0
135
+ hash: 2325908448554059919
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 1.8.23
139
+ signing_key:
140
+ specification_version: 3
141
+ summary: Makes it easy to use markdown with mongoid
142
+ test_files:
143
+ - spec/spec_helper.rb
144
+ - spec/unit/markdown_spec.rb