Skip to content
Browse files

Version 0.0.1.

  • Loading branch information...
0 parents commit d0f029084c62f97ead312e00afc8f70ea91701dd @gma committed
4 .gitignore
@@ -0,0 +1,4 @@
+*.gem
+.bundle
+Gemfile.lock
+pkg/*
7 Gemfile
@@ -0,0 +1,7 @@
+source "http://rubygems.org"
+
+# Specify your gem's dependencies in nesta-plugin-yaml-metadata.gemspec
+gemspec
+
+# gem 'nesta', :path => '../../nesta'
+# gem 'ruby-debug19'
1 Rakefile
@@ -0,0 +1 @@
+require "bundler/gem_tasks"
3 lib/nesta-plugin-yaml-metadata.rb
@@ -0,0 +1,3 @@
+require "nesta-plugin-yaml-metadata/version"
+
+Nesta::Plugin.register(__FILE__)
15 lib/nesta-plugin-yaml-metadata/init.rb
@@ -0,0 +1,15 @@
+require 'yaml'
+
+module Nesta
+ class FileModel
+ def parse_metadata(first_paragraph)
+ yaml = YAML.load(first_paragraph)
+ rescue Psych::SyntaxError
+ raise MetadataParseError
+ else
+ metadata = CaseInsensitiveHash.new
+ yaml.each { |key, value| metadata[key.downcase] = value }
+ metadata
+ end
+ end
+end
9 lib/nesta-plugin-yaml-metadata/version.rb
@@ -0,0 +1,9 @@
+module Nesta
+ module Plugin
+ module Yaml
+ module Metadata
+ VERSION = "0.0.1"
+ end
+ end
+ end
+end
34 nesta-plugin-yaml-metadata.gemspec
@@ -0,0 +1,34 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+require "nesta-plugin-yaml-metadata/version"
+
+Gem::Specification.new do |s|
+ s.name = "nesta-plugin-yaml-metadata"
+ s.version = Nesta::Plugin::Yaml::Metadata::VERSION
+ s.authors = ["Graham Ashton"]
+ s.email = ["graham@effectif.com"]
+ s.homepage = ""
+ s.summary = %q{Replaces Nesta's metadata syntax with Yaml}
+ s.description = <<EOF
+Pages of content in Nesta CMS can be embellished with metadata, written
+in a simple key/value pair syntax. If you'd like extra flexibility in
+your metadata, you can use this plugin to replace Nesta's built-in
+metadata parser with Ruby's Yaml parser.
+
+You still need to make sure that all the metadata is at the top of the
+page; the first blank line signifies the start of the page content.
+EOF
+
+ s.rubyforge_project = "nesta-plugin-yaml-metadata"
+
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.require_paths = ["lib"]
+
+ # specify any dependencies here; for example:
+ # s.add_development_dependency "rspec"
+ # s.add_runtime_dependency "rest-client"
+ s.add_dependency("nesta", ">= 0.9.12")
+ s.add_development_dependency("rake")
+end
0 test/fixtures/.gitkeep
No changes.
51 test/plugin_test.rb
@@ -0,0 +1,51 @@
+require 'fileutils'
+require 'test/unit'
+
+require 'tilt'
+require 'nesta/models'
+
+require_relative '../lib/nesta-plugin-yaml-metadata/init'
+
+class YamlMetadataPluginTest < Test::Unit::TestCase
+ def fixture
+ File.join(File.dirname(__FILE__), 'fixtures', 'test.mdown')
+ end
+
+ def create_fixture(filename)
+ File.open(filename, 'w') { |file| file.write yield }
+ end
+
+ def setup
+ create_fixture(fixture) do
+ <<-EOF
+---
+YAML key:
+ - value 1
+ - value 2
+
+# Page heading
+
+Well hello...
+ EOF
+ end
+ @page = Nesta::Page.new(fixture)
+ end
+
+ def teardown
+ FileUtils.rm(fixture) if File.exist?(fixture)
+ end
+
+ def test_should_convert_yaml_to_array
+ assert_equal ['value 1', 'value 2'], @page.metadata('yaml key')
+ end
+
+ def test_should_allow_keys_to_be_accessed_in_any_case
+ assert_equal ['value 1', 'value 2'], @page.metadata('YAML Key')
+ end
+
+ def test_should_raise_correct_exception_on_invalid_yaml
+ assert_raises(Nesta::MetadataParseError) do
+ @page.parse_metadata('foo: ["oops')
+ end
+ end
+end

0 comments on commit d0f0290

Please sign in to comment.
Something went wrong with that request. Please try again.