preamble 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.markdown +43 -0
- data/Rakefile +1 -0
- data/lib/preamble.rb +59 -0
- data/lib/preamble/version.rb +3 -0
- data/preamble.gemspec +20 -0
- metadata +63 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.markdown
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
Preamble
|
2
|
+
========
|
3
|
+
|
4
|
+
Introduction
|
5
|
+
------------
|
6
|
+
|
7
|
+
The preamble gem lets you add a yaml preamble to your files, much like the Jekyll static site generator
|
8
|
+
|
9
|
+
|
10
|
+
Example
|
11
|
+
-------
|
12
|
+
|
13
|
+
---
|
14
|
+
key1: value1
|
15
|
+
key2: [1, 2, 3]
|
16
|
+
---
|
17
|
+
|
18
|
+
Your body content goes here.
|
19
|
+
|
20
|
+
|
21
|
+
Usage
|
22
|
+
-----
|
23
|
+
|
24
|
+
Preamble.load("./file.xyz")
|
25
|
+
Preamble.load_multiple("./file.xyz", "./file.abc")
|
26
|
+
|
27
|
+
|
28
|
+
Output
|
29
|
+
------
|
30
|
+
|
31
|
+
The Preamble.load function returns an array. The first part is your data, the second is the body conent.
|
32
|
+
|
33
|
+
[ { "key1" => "value1", "key2" => [1, 2, 3] }, "\nYour body content goes here"]
|
34
|
+
|
35
|
+
|
36
|
+
Notes
|
37
|
+
-----
|
38
|
+
|
39
|
+
1. The preamble must begin and end with three dashes '---'
|
40
|
+
2. Whitespace can go above the preamble, but no content
|
41
|
+
3. This gem is template-agnostic. It doesn't care what your body content is. It just gives it to you as a string.
|
42
|
+
|
43
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/lib/preamble.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require "preamble/version"
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
module Preamble
|
5
|
+
|
6
|
+
def self.load(path)
|
7
|
+
|
8
|
+
preamble_lines = []
|
9
|
+
body_lines = []
|
10
|
+
|
11
|
+
state = :before_preamble
|
12
|
+
|
13
|
+
open(path).each do |line|
|
14
|
+
|
15
|
+
stripped = line.strip
|
16
|
+
|
17
|
+
case state
|
18
|
+
|
19
|
+
when :before_preamble
|
20
|
+
|
21
|
+
new_state = case stripped
|
22
|
+
when "---"
|
23
|
+
:preamble
|
24
|
+
when ""
|
25
|
+
:before_preamble
|
26
|
+
else
|
27
|
+
raise "First line must begin with ---"
|
28
|
+
end
|
29
|
+
|
30
|
+
when :preamble
|
31
|
+
|
32
|
+
new_state = case stripped
|
33
|
+
when "---"
|
34
|
+
:after_preamble
|
35
|
+
else
|
36
|
+
preamble_lines << line
|
37
|
+
:preamble
|
38
|
+
end
|
39
|
+
|
40
|
+
when :after_preamble
|
41
|
+
new_state = :after_preamble
|
42
|
+
body_lines << line
|
43
|
+
|
44
|
+
else raise "Invalid State: #{ state }"
|
45
|
+
end
|
46
|
+
|
47
|
+
state = new_state
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
return [YAML::load(preamble_lines.join), body_lines.join]
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.load_multiple(*paths)
|
56
|
+
paths.map{ |path| Preamble.load(path) }
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
data/preamble.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "preamble/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "preamble"
|
7
|
+
s.version = Preamble::VERSION
|
8
|
+
s.authors = ["Starr Horne"]
|
9
|
+
s.email = ["starr@chromahq.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{Use yaml preambles in your documents & templates}
|
12
|
+
s.description = %q{Allows you to add YAML front matter to your templates. Useful for adding metadata to static pages}
|
13
|
+
|
14
|
+
s.rubyforge_project = "preamble"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: preamble
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Starr Horne
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-06-26 00:00:00 -05:00
|
14
|
+
default_executable:
|
15
|
+
dependencies: []
|
16
|
+
|
17
|
+
description: Allows you to add YAML front matter to your templates. Useful for adding metadata to static pages
|
18
|
+
email:
|
19
|
+
- starr@chromahq.com
|
20
|
+
executables: []
|
21
|
+
|
22
|
+
extensions: []
|
23
|
+
|
24
|
+
extra_rdoc_files: []
|
25
|
+
|
26
|
+
files:
|
27
|
+
- .gitignore
|
28
|
+
- Gemfile
|
29
|
+
- README.markdown
|
30
|
+
- Rakefile
|
31
|
+
- lib/preamble.rb
|
32
|
+
- lib/preamble/version.rb
|
33
|
+
- preamble.gemspec
|
34
|
+
has_rdoc: true
|
35
|
+
homepage: ""
|
36
|
+
licenses: []
|
37
|
+
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: "0"
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: "0"
|
55
|
+
requirements: []
|
56
|
+
|
57
|
+
rubyforge_project: preamble
|
58
|
+
rubygems_version: 1.6.2
|
59
|
+
signing_key:
|
60
|
+
specification_version: 3
|
61
|
+
summary: Use yaml preambles in your documents & templates
|
62
|
+
test_files: []
|
63
|
+
|