nesta-plugin-yaml-metadata 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in nesta-plugin-yaml-metadata.gemspec
4
+ gemspec
5
+
6
+ # gem 'nesta', :path => '../../nesta'
7
+ # gem 'ruby-debug19'
@@ -0,0 +1,19 @@
1
+ # Yaml metadata plugin for Nesta
2
+
3
+ Pages of content in [Nesta CMS][] can be embellished with metadata,
4
+ written in a simple key/value pair syntax. If you'd like extra
5
+ flexibility in your metadata, you can use this plugin to replace Nesta's
6
+ built-in metadata parser with Ruby's Yaml parser.
7
+
8
+ You still need to make sure that all the metadata is at the top of the
9
+ page; the first blank line signifies the start of the page content.
10
+
11
+ To use the plugin just add it to your project's `Gemfile` and rebuild
12
+ your bundle:
13
+
14
+ $ echo 'gem "nesta-plugin-yaml-metadata"' >> Gemfile
15
+ $ bundle
16
+
17
+ It requires Nesta 0.9.12 or later.
18
+
19
+ [Nesta CMS]: http://nestacms.com
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,3 @@
1
+ require "nesta-plugin-yaml-metadata/version"
2
+
3
+ Nesta::Plugin.register(__FILE__)
@@ -0,0 +1,16 @@
1
+ require 'yaml'
2
+
3
+ module Nesta
4
+ class FileModel
5
+ def parse_metadata(first_paragraph)
6
+ yaml = YAML.load(first_paragraph)
7
+ rescue Psych::SyntaxError
8
+ raise MetadataParseError
9
+ else
10
+ raise MetadataParseError unless yaml
11
+ metadata = CaseInsensitiveHash.new
12
+ yaml.each { |key, value| metadata[key.downcase] = value } if yaml
13
+ metadata
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,9 @@
1
+ module Nesta
2
+ module Plugin
3
+ module Yaml
4
+ module Metadata
5
+ VERSION = "0.0.1"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,34 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "nesta-plugin-yaml-metadata/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "nesta-plugin-yaml-metadata"
7
+ s.version = Nesta::Plugin::Yaml::Metadata::VERSION
8
+ s.authors = ["Graham Ashton"]
9
+ s.email = ["graham@effectif.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Replaces Nesta's metadata syntax with Yaml}
12
+ s.description = <<EOF
13
+ Pages of content in Nesta CMS can be embellished with metadata, written
14
+ in a simple key/value pair syntax. If you'd like extra flexibility in
15
+ your metadata, you can use this plugin to replace Nesta's built-in
16
+ metadata parser with Ruby's Yaml parser.
17
+
18
+ You still need to make sure that all the metadata is at the top of the
19
+ page; the first blank line signifies the start of the page content.
20
+ EOF
21
+
22
+ s.rubyforge_project = "nesta-plugin-yaml-metadata"
23
+
24
+ s.files = `git ls-files`.split("\n")
25
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
26
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
27
+ s.require_paths = ["lib"]
28
+
29
+ # specify any dependencies here; for example:
30
+ # s.add_development_dependency "rspec"
31
+ # s.add_runtime_dependency "rest-client"
32
+ s.add_dependency("nesta", ">= 0.9.12")
33
+ s.add_development_dependency("rake")
34
+ end
File without changes
@@ -0,0 +1,57 @@
1
+ require 'fileutils'
2
+ require 'test/unit'
3
+
4
+ require 'tilt'
5
+ require 'nesta/models'
6
+
7
+ require_relative '../lib/nesta-plugin-yaml-metadata/init'
8
+
9
+ class YamlMetadataPluginTest < Test::Unit::TestCase
10
+ def fixture
11
+ File.join(File.dirname(__FILE__), 'fixtures', 'test.mdown')
12
+ end
13
+
14
+ def create_fixture(filename)
15
+ File.open(filename, 'w') { |file| file.write yield }
16
+ end
17
+
18
+ def setup
19
+ create_fixture(fixture) do
20
+ <<-EOF
21
+ ---
22
+ YAML key:
23
+ - value 1
24
+ - value 2
25
+
26
+ # Page heading
27
+
28
+ Well hello...
29
+ EOF
30
+ end
31
+ @page = Nesta::Page.new(fixture)
32
+ end
33
+
34
+ def teardown
35
+ FileUtils.rm(fixture) if File.exist?(fixture)
36
+ end
37
+
38
+ def test_should_convert_yaml_to_array
39
+ assert_equal ['value 1', 'value 2'], @page.metadata('yaml key')
40
+ end
41
+
42
+ def test_should_allow_keys_to_be_accessed_in_any_case
43
+ assert_equal ['value 1', 'value 2'], @page.metadata('YAML Key')
44
+ end
45
+
46
+ def test_should_raise_parse_error_on_invalid_yaml
47
+ assert_raises(Nesta::MetadataParseError) do
48
+ @page.parse_metadata('foo: ["oops')
49
+ end
50
+ end
51
+
52
+ def test_should_raise_parse_error_when_no_metadata_specified
53
+ assert_raises(Nesta::MetadataParseError) do
54
+ @page.parse_metadata('# Page heading')
55
+ end
56
+ end
57
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nesta-plugin-yaml-metadata
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Graham Ashton
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-03-03 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ prerelease: false
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ hash: 35
28
+ segments:
29
+ - 0
30
+ - 9
31
+ - 12
32
+ version: 0.9.12
33
+ version_requirements: *id001
34
+ name: nesta
35
+ type: :runtime
36
+ - !ruby/object:Gem::Dependency
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ version_requirements: *id002
48
+ name: rake
49
+ type: :development
50
+ description: |
51
+ Pages of content in Nesta CMS can be embellished with metadata, written
52
+ in a simple key/value pair syntax. If you'd like extra flexibility in
53
+ your metadata, you can use this plugin to replace Nesta's built-in
54
+ metadata parser with Ruby's Yaml parser.
55
+
56
+ You still need to make sure that all the metadata is at the top of the
57
+ page; the first blank line signifies the start of the page content.
58
+
59
+ email:
60
+ - graham@effectif.com
61
+ executables: []
62
+
63
+ extensions: []
64
+
65
+ extra_rdoc_files: []
66
+
67
+ files:
68
+ - .gitignore
69
+ - Gemfile
70
+ - README.md
71
+ - Rakefile
72
+ - lib/nesta-plugin-yaml-metadata.rb
73
+ - lib/nesta-plugin-yaml-metadata/init.rb
74
+ - lib/nesta-plugin-yaml-metadata/version.rb
75
+ - nesta-plugin-yaml-metadata.gemspec
76
+ - test/fixtures/.gitkeep
77
+ - test/plugin_test.rb
78
+ homepage: ""
79
+ licenses: []
80
+
81
+ post_install_message:
82
+ rdoc_options: []
83
+
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ hash: 3
92
+ segments:
93
+ - 0
94
+ version: "0"
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ hash: 3
101
+ segments:
102
+ - 0
103
+ version: "0"
104
+ requirements: []
105
+
106
+ rubyforge_project: nesta-plugin-yaml-metadata
107
+ rubygems_version: 1.8.17
108
+ signing_key:
109
+ specification_version: 3
110
+ summary: Replaces Nesta's metadata syntax with Yaml
111
+ test_files:
112
+ - test/fixtures/.gitkeep
113
+ - test/plugin_test.rb