metadown 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/.rvmrc +1 -0
- data/.yardopts +4 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +67 -0
- data/Rakefile +2 -0
- data/lib/metadown.rb +15 -0
- data/lib/metadown/renderer.rb +17 -0
- data/lib/metadown/version.rb +3 -0
- data/metadown.gemspec +23 -0
- data/spec/metadown_spec.rb +19 -0
- data/spec/renderer_spec.rb +33 -0
- metadata +106 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm --create 1.9.3@metadown
|
data/.yardopts
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Steve Klabnik
|
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,67 @@
|
|
1
|
+
# Metadown
|
2
|
+
|
3
|
+
tl;dr... This gem gives you a custom markdown parser that allows you to prefix the
|
4
|
+
markdown itself with YAML metadata.
|
5
|
+
|
6
|
+
Sometimes, just having plain markdown isn't good enough. Say you're writing
|
7
|
+
a blog post, and you want to include some information about the post itself,
|
8
|
+
such as the date and time it was posted. Keeping it in a separate file seems
|
9
|
+
like a bad idea, but Markdown doesn't have any good way of doing this.
|
10
|
+
|
11
|
+
Enter [Jekyll](https://github.com/mojombo/jekyll). It lets you put some YAML
|
12
|
+
at the head of your file:
|
13
|
+
|
14
|
+
---
|
15
|
+
layout: post
|
16
|
+
title: An Awesome Blog Post
|
17
|
+
---
|
18
|
+
|
19
|
+
Four score and seven years ago,
|
20
|
+
|
21
|
+
Woudn't that be neat to use on other projects? I thought so too! Hence,
|
22
|
+
metadown.
|
23
|
+
|
24
|
+
## Installation
|
25
|
+
|
26
|
+
Add this line to your application's Gemfile:
|
27
|
+
|
28
|
+
gem 'metadown'
|
29
|
+
|
30
|
+
And then execute:
|
31
|
+
|
32
|
+
$ bundle
|
33
|
+
|
34
|
+
Or install it yourself as:
|
35
|
+
|
36
|
+
$ gem install metadown
|
37
|
+
|
38
|
+
## Usage
|
39
|
+
|
40
|
+
Metadown might have the simplest API I've ever written: one method! Just send
|
41
|
+
the string with the metadown you want rendered, and boom! You get an object
|
42
|
+
back with two attributes: output and metadata.
|
43
|
+
|
44
|
+
require 'metadown'
|
45
|
+
|
46
|
+
data = Metadown.render("hello world")
|
47
|
+
data.output #=> "<p>hello, world</p>"
|
48
|
+
data.metadata #=> "{}"
|
49
|
+
|
50
|
+
text = <<-MARKDOWN
|
51
|
+
---
|
52
|
+
key: "value"
|
53
|
+
---
|
54
|
+
hello world
|
55
|
+
MARKDOWN
|
56
|
+
|
57
|
+
data = Metadown.render(text)
|
58
|
+
data.output #=> "<p>hello, world</p>\n"
|
59
|
+
data.metadata #=> {"key" => "value"}
|
60
|
+
|
61
|
+
## Contributing
|
62
|
+
|
63
|
+
1. Fork it
|
64
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
65
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
66
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
67
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/metadown.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require "metadown/renderer"
|
2
|
+
require "metadown/version"
|
3
|
+
|
4
|
+
module Metadown
|
5
|
+
|
6
|
+
Data = Struct.new(:metadata, :output)
|
7
|
+
|
8
|
+
def render(text)
|
9
|
+
renderer = Metadown::Renderer.new
|
10
|
+
markdown = Redcarpet::Markdown.new(renderer)
|
11
|
+
output = markdown.render(text)
|
12
|
+
Data.new(renderer.metadata, output)
|
13
|
+
end
|
14
|
+
module_function :render
|
15
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'redcarpet'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
module Metadown
|
5
|
+
class Renderer < Redcarpet::Render::HTML
|
6
|
+
def preprocess(full_document)
|
7
|
+
full_document =~ /^(---\s*\n.*?\n?)^(---\s*$\n?)/m
|
8
|
+
@metadata = YAML.load($1) if $1
|
9
|
+
|
10
|
+
$' or full_document
|
11
|
+
end
|
12
|
+
|
13
|
+
def metadata
|
14
|
+
@metadata || {}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/metadown.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/metadown/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Steve Klabnik"]
|
6
|
+
gem.email = ["steve@steveklabnik.com"]
|
7
|
+
gem.description = %q{This gem gives you a custom markdown parser that allows you to prefix the markdown itself with YAML metadata.}
|
8
|
+
gem.summary = %q{Annotate your Markdown files with metadata.}
|
9
|
+
gem.homepage = "http://rubydoc.info/github/steveklabnik/metadown/1.0.0/file/README.md"
|
10
|
+
|
11
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
13
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
gem.name = "metadown"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Metadown::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency "redcarpet"
|
19
|
+
|
20
|
+
gem.add_development_dependency "rspec"
|
21
|
+
gem.add_development_dependency "rake"
|
22
|
+
gem.add_development_dependency "yard"
|
23
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
$:.unshift("lib")
|
2
|
+
require 'metadown'
|
3
|
+
|
4
|
+
describe Metadown do
|
5
|
+
it "provides a factory" do
|
6
|
+
text = <<-MARKDOWN
|
7
|
+
---
|
8
|
+
key: "value"
|
9
|
+
---
|
10
|
+
hello world
|
11
|
+
MARKDOWN
|
12
|
+
|
13
|
+
Metadown.render(text).tap do |data|
|
14
|
+
data.should be_kind_of(Metadown::Data)
|
15
|
+
data.metadata.should eql({"key" => "value"})
|
16
|
+
data.output.should eql("<p>hello world</p>\n")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
$:.unshift("lib")
|
2
|
+
require 'metadown/renderer'
|
3
|
+
|
4
|
+
describe Metadown::Renderer do
|
5
|
+
it "is a redcarpet renderer" do
|
6
|
+
subject.should be_kind_of(Redcarpet::Render::HTML)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "renders markdown" do
|
10
|
+
r = Redcarpet::Markdown.new(subject)
|
11
|
+
r.render("hello world").should eql("<p>hello world</p>\n")
|
12
|
+
end
|
13
|
+
|
14
|
+
it "extracts YAML" do
|
15
|
+
r = Redcarpet::Markdown.new(subject)
|
16
|
+
text = <<-MARKDOWN
|
17
|
+
---
|
18
|
+
key: "value"
|
19
|
+
---
|
20
|
+
hello world
|
21
|
+
MARKDOWN
|
22
|
+
|
23
|
+
r.render text
|
24
|
+
|
25
|
+
subject.metadata.should eql({"key"=>"value"})
|
26
|
+
end
|
27
|
+
|
28
|
+
it "gives {} for no metadata" do
|
29
|
+
Redcarpet::Markdown.new(subject).render("hello world")
|
30
|
+
|
31
|
+
subject.metadata.should eql({})
|
32
|
+
end
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: metadown
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Steve Klabnik
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-01-23 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: redcarpet
|
16
|
+
requirement: &2160435780 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2160435780
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
requirement: &2160434900 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2160434900
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rake
|
38
|
+
requirement: &2160434460 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *2160434460
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: yard
|
49
|
+
requirement: &2160433940 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *2160433940
|
58
|
+
description: This gem gives you a custom markdown parser that allows you to prefix
|
59
|
+
the markdown itself with YAML metadata.
|
60
|
+
email:
|
61
|
+
- steve@steveklabnik.com
|
62
|
+
executables: []
|
63
|
+
extensions: []
|
64
|
+
extra_rdoc_files: []
|
65
|
+
files:
|
66
|
+
- .gitignore
|
67
|
+
- .rvmrc
|
68
|
+
- .yardopts
|
69
|
+
- Gemfile
|
70
|
+
- LICENSE
|
71
|
+
- README.md
|
72
|
+
- Rakefile
|
73
|
+
- lib/metadown.rb
|
74
|
+
- lib/metadown/renderer.rb
|
75
|
+
- lib/metadown/version.rb
|
76
|
+
- metadown.gemspec
|
77
|
+
- spec/metadown_spec.rb
|
78
|
+
- spec/renderer_spec.rb
|
79
|
+
homepage: http://rubydoc.info/github/steveklabnik/metadown/1.0.0/file/README.md
|
80
|
+
licenses: []
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ! '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
none: false
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 1.8.10
|
100
|
+
signing_key:
|
101
|
+
specification_version: 3
|
102
|
+
summary: Annotate your Markdown files with metadata.
|
103
|
+
test_files:
|
104
|
+
- spec/metadown_spec.rb
|
105
|
+
- spec/renderer_spec.rb
|
106
|
+
has_rdoc:
|