contentful_middleman 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ccfe1bc9ea0a8cfa76de3d65aa382141e3d81da0
4
+ data.tar.gz: 5929f5f756b15d636a17e575a40c81bf3f0b1230
5
+ SHA512:
6
+ metadata.gz: ece6120ab1f940ce2bd6dac04a5ef093d322caf057e4f17a247362445b7a61b6eac19f35da0eef2e9c3f00b56f9417a19ebc1fab5fc8440c2e2a0dd16ea5bcc8
7
+ data.tar.gz: d20282b168ad58b84b9d77400dbaa01d9527d776119dd2510263f8de3b32cd824bb330ade6045ad17e77221185032938d94d51b93a8d71213e77e2d6e975d1ff
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile*.lock
4
+ pkg/*
5
+ .rvmrc
6
+ .DS_Store
7
+ .rbenv-version
8
+ .ruby-version
9
+ tmp
10
+ doc
11
+ .yardoc
12
+ build/
13
+ .sass-cache
14
+ coverage
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ rvm:
2
+ - 1.9.3
3
+ - 2.0.0
4
+ - jruby-19mode
5
+
6
+ script: "bundle exec rake test"
7
+
8
+ env: TEST=true
data/.yardopts ADDED
@@ -0,0 +1,3 @@
1
+ lib/**/*.rb
2
+ --no-private
3
+ --hide-void-return
data/CHANGELOG.md ADDED
@@ -0,0 +1,15 @@
1
+ 0.0.4
2
+ ===
3
+
4
+ * Publish first Gem version
5
+
6
+ 0.0.3
7
+ ===
8
+
9
+ * Minor updates
10
+
11
+
12
+ 0.0.2
13
+ ===
14
+
15
+ * First release
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,43 @@
1
+ # Contributing
2
+ In the spirit of [free software][free-sw], **everyone** is encouraged to help
3
+ improve this project.
4
+
5
+ [free-sw]: http://www.fsf.org/licensing/essays/free-sw.html
6
+
7
+ Here are some ways *you* can contribute:
8
+
9
+ * by using alpha, beta, and prerelease versions
10
+ * by reporting bugs
11
+ * by suggesting new features
12
+ * by writing or editing documentation
13
+ * by writing specifications
14
+ * by writing code ( **no patch is too small** : fix typos, add comments, clean up inconsistent whitespace )
15
+ * by refactoring code
16
+ * by closing [issues][]
17
+ * by reviewing patches
18
+
19
+ [issues]: https://github.com/middleman/middleman-blog/issues
20
+
21
+ ## Submitting an Issue
22
+ We use the [GitHub issue tracker][issues] to track bugs and features. Before
23
+ submitting a bug report or feature request, check to make sure it hasn't
24
+ already been submitted. When submitting a bug report, please include a [Gist][]
25
+ that includes a stack trace and any details that may be necessary to reproduce
26
+ the bug, including your gem version, Ruby version, and operating system.
27
+ Ideally, a bug report should include a pull request with failing specs.
28
+
29
+ [gist]: https://gist.github.com/
30
+
31
+ ## Submitting a Pull Request
32
+ 1. [Fork the repository.][fork]
33
+ 2. [Create a topic branch.][branch]
34
+ 3. Add specs for your unimplemented feature or bug fix.
35
+ 4. Run `bundle exec rake test`. If your specs pass, return to step 3.
36
+ 5. Implement your feature or bug fix.
37
+ 6. Run `bundle exec rake test`. If your specs fail, return to step 5.
38
+ 7. Add, commit, and push your changes.
39
+ 8. [Submit a pull request.][pr]
40
+
41
+ [fork]: http://help.github.com/fork-a-repo/
42
+ [branch]: http://learn.github.com/p/branching.html
43
+ [pr]: http://help.github.com/send-pull-requests/
data/Gemfile ADDED
@@ -0,0 +1,18 @@
1
+ # If you have OpenSSL installed, we recommend updating
2
+ # the following line to use "https"
3
+ source 'http://rubygems.org'
4
+
5
+ gem "middleman-core", :github => "middleman/middleman", :branch => 'v3-stable'
6
+
7
+ # Specify your gem's dependencies in contentful_middleman.gemspec
8
+ gemspec
9
+
10
+ gem "rake"
11
+ gem "yard"
12
+
13
+ # Test tools
14
+ gem "rspec"
15
+ gem "simplecov"
16
+
17
+ gem "cane", :platforms => [:mri_19, :mri_20], :require => false
18
+ gem 'coveralls', :require => false
data/LICENSE.md ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2014 Contentful GmbH
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,83 @@
1
+ # Contentful Middleman
2
+
3
+ [![Build Status](https://travis-ci.org/contentful/contentful_middleman.png)](https://travis-ci.org/contentful/contentful_middleman)
4
+
5
+ Contentful Middleman is a [Middleman](http://middlemanapp.com/) extension to use the Middleman static side generator together with the API-driven [Contentful CMS](https://www.contentful.com). It is powered by the [Contentful Ruby Gem](https://github.com/contentful/contentful.rb).
6
+
7
+ Experience the power of Middleman while staying sane as a developer by letting end-users edit content in a web-based interface.
8
+
9
+ This extensions supports both page-based content as well as blog posts through middleman-blog.
10
+
11
+ ## Installation
12
+
13
+ Add the following line to the Gemfile of your Middleman project:
14
+
15
+ ```
16
+ gem "contentful_middleman"
17
+ ```
18
+
19
+ Then as usual, run:
20
+
21
+ ```
22
+ bundle install
23
+ ```
24
+
25
+ ## Configuration
26
+
27
+ To configure the extension, add the following configuration block to Middleman's config.rb:
28
+
29
+ ```
30
+ activate :contentful do |f|
31
+ # The Space ID of your Contentful space
32
+ f.space = 'YOUR_SPACE_ID'
33
+
34
+ # The access token (API Key) for the Content Delivery API
35
+ f.access_token = 'YOUR_CONTENT_DELIVERY_API_ACCESS_TOKEN'
36
+
37
+ # Optional: Options for middleman-blog
38
+
39
+ # Filter Entries for your blog posts. See Contentful gem and Content Delivery API documentation.
40
+ f.blog_posts_query = {content_type: "6LbnqgnwA08qYaU", category: "news" }
41
+
42
+ # Which keys to use in the article template for blog posts
43
+ # Key: template variable
44
+ # Value: Entry method or block
45
+ f.blog_post_mappings = {
46
+ slug: :id,
47
+ date: :created_at,
48
+ body: :id,
49
+ tags: :tags,
50
+ title: ->(e){"#{e.id}XXXX"}
51
+ }
52
+
53
+ # Define your own template for blog posts
54
+ f.new_article_template = "/my_templates/article.tt"
55
+
56
+ # Automatically synchronize blog posts before building with "middleman build"
57
+ f.sync_blog_before_build = true # default: false
58
+ end
59
+ ```
60
+
61
+ ## Using managed content in regular pages
62
+
63
+ The `contentful` helper provides a Contentful gem client object, that can be used to fetch managed content from Contentful:
64
+
65
+ ```
66
+ <ol>
67
+ <% contentful.entries(content_type: '6LbnqgnwA08qYaU').each do |entry| %>
68
+ <li>
69
+ <%= entry.title %>
70
+ <%= entry.body %>
71
+ <%= entry.created_at %>
72
+ </li>
73
+ <% end %>
74
+ </ol>
75
+ ```
76
+
77
+ ## Synchronizing blog posts manually
78
+
79
+ Blog posts are synchronized to your repo as YAML files with front matter, just as if you would write them manually. Either automatically when building, or manually by running:
80
+
81
+ ```
82
+ middleman contentful
83
+ ```
data/Rakefile ADDED
@@ -0,0 +1,36 @@
1
+ require 'middleman-core'
2
+
3
+ require 'rake/clean'
4
+
5
+ desc "Run tests, both RSpec and Cucumber"
6
+ task :test => [:spec]
7
+
8
+ require 'rspec/core/rake_task'
9
+ desc "Run RSpec"
10
+ RSpec::Core::RakeTask.new do |spec|
11
+ spec.pattern = 'spec/**/*_spec.rb'
12
+ spec.rspec_opts = ['--color', '--format nested']
13
+ end
14
+
15
+ begin
16
+ require 'cane/rake_task'
17
+
18
+ desc "Run cane to check quality metrics"
19
+ Cane::RakeTask.new(:quality) do |cane|
20
+ cane.no_style = true
21
+ cane.no_doc = true
22
+ cane.abc_glob = "lib/contentful_middleman/**/*.rb"
23
+ end
24
+ rescue LoadError
25
+ # warn "cane not available, quality task not provided."
26
+ end
27
+
28
+ desc "Build HTML documentation"
29
+ task :doc do
30
+ sh 'bundle exec yard'
31
+ end
32
+
33
+ require 'rake'
34
+
35
+ require 'rubygems/tasks'
36
+ Gem::Tasks.new
data/TODO ADDED
@@ -0,0 +1,15 @@
1
+ - add specs
2
+ - add travis ci
3
+
4
+ - publish yard docs
5
+ - add comments
6
+
7
+ - support multiple instances and blog instances
8
+
9
+ - building through webhook
10
+ - preview mode
11
+
12
+ - blog posts
13
+ - add draft?
14
+ - add ignore?
15
+ - use title field from content type
@@ -0,0 +1,28 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "contentful_middleman/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "contentful_middleman"
7
+ s.version = ContentfulMiddleman::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Sascha Konietzke"]
10
+ s.email = ["sascha@contentful.com"]
11
+ s.homepage = "https://www.contentful.com"
12
+ s.summary = %q{Include mangablable content from the Contentful CMS and API into your Middleman projects}
13
+ s.description = %q{Load blog posts and other managed content into Middleman}
14
+ s.license = "MIT"
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
+
21
+ # The version of middleman-core your extension depends on
22
+ s.add_dependency("middleman-core", ["~> 3.3"])
23
+
24
+ # Additional dependencies
25
+ s.add_dependency("contentful")
26
+
27
+ s.add_development_dependency 'rubygems-tasks', '~> 0.2'
28
+ end
@@ -0,0 +1,7 @@
1
+ require "middleman-core"
2
+
3
+ require 'contentful_middleman/version'
4
+ require 'contentful_middleman/core'
5
+ require "contentful_middleman/commands/sync_blog"
6
+
7
+ ::Middleman::Extensions.register(:contentful, ContentfulMiddleman::Core)
@@ -0,0 +1,9 @@
1
+ ---
2
+ # Warning: This file is auto-generated from the Contentful CMS. Local changes will overriden on next sync.
3
+
4
+ title: <%= @title %>
5
+ date: <%= @date.strftime('%F %R %Z') %>
6
+ tags: <%= @tags.join(', ') %>
7
+ ---
8
+
9
+ <%= @body %>
@@ -0,0 +1,88 @@
1
+ require 'middleman-core/cli'
2
+ require 'date'
3
+ require 'middleman-blog/uri_templates'
4
+
5
+ module Middleman
6
+ module Cli
7
+ # This class provides an "contentful" command for the middleman CLI.
8
+ class SyncBlog < Thor
9
+ include Thor::Actions
10
+ include ::Middleman::Blog::UriTemplates
11
+
12
+ check_unknown_options!
13
+
14
+ namespace :contentful
15
+
16
+ def self.source_root
17
+ ENV['MM_ROOT']
18
+ end
19
+
20
+ # Tell Thor to exit with a nonzero exit code on failure
21
+ def self.exit_on_failure?
22
+ true
23
+ end
24
+
25
+ desc "contentful", "Synchronize Contentful blog posts"
26
+ method_option "lang",
27
+ aliases: "-l",
28
+ desc: "The language to create the post with (defaults to I18n.default_locale if avaliable)"
29
+ method_option "blog",
30
+ aliases: "-b",
31
+ desc: "The name of the blog to create the post inside (for multi-blog apps, defaults to the only blog in single-blog apps)"
32
+ def contentful
33
+ contentful_middleman = shared_instance.contentful_middleman
34
+ client = shared_instance.contentful_middleman_client
35
+ contentful_middleman_options = contentful_middleman.options
36
+ blog_post_mappings = contentful_middleman.blog_post_mappings
37
+
38
+ if shared_instance.respond_to? :blog
39
+ shared_instance.logger.info " Contentful Sync: Start..."
40
+
41
+ client.entries(contentful_middleman_options.blog_posts_query).each do |entry|
42
+ slug = value_from_object(entry, blog_post_mappings[:slug])
43
+ title = value_from_object(entry, blog_post_mappings[:title])
44
+ date = value_from_object(entry, blog_post_mappings[:date]).strftime("%Y-%m-%d")
45
+ tags = value_from_object(entry, blog_post_mappings[:tags]) || []
46
+ body = value_from_object(entry, blog_post_mappings[:body])
47
+
48
+ @title = title
49
+ @slug = slug || safe_parameterize(title)
50
+ @date = date ? Time.zone.parse(date) : Time.zone.now
51
+ @tags = tags
52
+ @lang = options[:lang] || ( I18n.default_locale if defined? I18n )
53
+ @body = body
54
+
55
+ blog_inst = shared_instance.blog(options[:blog])
56
+
57
+ path_template = blog_inst.source_template
58
+ params = date_to_params(@date).merge(lang: @lang.to_s, title: @slug)
59
+ article_path = apply_uri_template path_template, params
60
+
61
+ template contentful_middleman.options.new_article_template, File.join(shared_instance.source_dir, article_path + blog_inst.options.default_extension)
62
+ end
63
+
64
+ shared_instance.logger.info " Contentful Sync: Done!"
65
+ else
66
+ raise Thor::Error.new "You need to activate the blog extension in config.rb before you can create an article"
67
+ end
68
+ end
69
+
70
+ private
71
+ def shared_instance
72
+ @shared_instance ||= ::Middleman::Application.server.inst
73
+ end
74
+
75
+ def value_from_object(object, mapping)
76
+ if ( mapping.is_a?(Symbol) || mapping.is_a?(String) ) && object.respond_to?(mapping)
77
+ object.send(mapping)
78
+ elsif mapping.is_a?(Proc)
79
+ object.instance_exec(object, &mapping)
80
+ else
81
+ shared_instance.logger.warn "Warning - Unknown mapping (#{mapping}) for object (#{object.class}) with ID (#{object.id})"
82
+ nil
83
+ end
84
+ end
85
+ end
86
+
87
+ end
88
+ end
@@ -0,0 +1,69 @@
1
+ require 'middleman-core'
2
+ require 'contentful'
3
+
4
+ # The Contentful Middleman extensions allows to load managed content into Middleman projects through the Contentful Content Management Platform.
5
+ module ContentfulMiddleman
6
+ class Core < ::Middleman::Extension
7
+ DEFAULT_BLOG_MAPPINGS = {
8
+ slug: :id,
9
+ date: :created_at,
10
+ title: :id,
11
+ body: :id,
12
+ tags: :tags
13
+ }
14
+
15
+ self.supports_multiple_instances = false
16
+
17
+ option :space, nil, 'The Contentful Space ID'
18
+ option :access_token, nil, 'The Contentful Content Delivery API access token'
19
+
20
+ option :new_article_template, File.expand_path('../commands/article.tt', __FILE__), 'Path (relative to project root) to an ERb template that will be used to generate new Contentful articles from the "middleman contentful" command.'
21
+
22
+ option :blog_posts_query, {}, "The conditions that are used on the Content Delivery API to query for blog posts"
23
+ option :blog_post_mappings, {}, "The mappings from Contentful DynamicResources to Middleman"
24
+
25
+ option :sync_blog_before_build, false, "Synchronize the blog from Contentful before the build phase"
26
+
27
+ def initialize(app, options_hash={}, &block)
28
+ super
29
+
30
+ app.set :contentful_middleman, self
31
+ app.set :contentful_middleman_client, client
32
+
33
+ app.before_build do |builder|
34
+ contentful_middleman.sync_blog if contentful_middleman.middleman_blog_enabled? && contentful_middleman.options.sync_blog_before_build
35
+ end
36
+ end
37
+
38
+ # Is the Middleman blog extension enabled?
39
+ def middleman_blog_enabled?
40
+ app.respond_to? :blog
41
+ end
42
+
43
+ # Synchronize blog posts from Contentful through the CLI task
44
+ def sync_blog
45
+ Middleman::Cli::SyncBlog.new.contentful
46
+ true
47
+ end
48
+
49
+ def blog_post_mappings
50
+ @blog_post_mappings ||= ContentfulMiddleman::Core::DEFAULT_BLOG_MAPPINGS.merge(options.blog_post_mappings)
51
+ end
52
+
53
+ # The Contentful Gem client for the Content Delivery API
54
+ def client
55
+ @client ||= Contentful::Client.new(
56
+ access_token: options.access_token,
57
+ space: options.space,
58
+ dynamic_entries: :auto
59
+ )
60
+ end
61
+
62
+ helpers do
63
+ # A helper method to access the Contentful Gem client
64
+ def contentful
65
+ contentful_middleman_client
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,3 @@
1
+ module ContentfulMiddleman
2
+ VERSION = "0.0.4"
3
+ end
@@ -0,0 +1 @@
1
+ require 'contentful_middleman'
@@ -0,0 +1,7 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ describe 'ContentfulMiddleman' do
4
+ it "should be pending" do
5
+ pending
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ require 'simplecov'
2
+ SimpleCov.root(File.expand_path(File.dirname(__FILE__) + '/..'))
3
+
4
+ require 'coveralls'
5
+ Coveralls.wear!
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: contentful_middleman
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
+ platform: ruby
6
+ authors:
7
+ - Sascha Konietzke
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: middleman-core
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '3.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '3.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: contentful
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubygems-tasks
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '0.2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '0.2'
55
+ description: Load blog posts and other managed content into Middleman
56
+ email:
57
+ - sascha@contentful.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - .travis.yml
64
+ - .yardopts
65
+ - CHANGELOG.md
66
+ - CONTRIBUTING.md
67
+ - Gemfile
68
+ - LICENSE.md
69
+ - README.md
70
+ - Rakefile
71
+ - TODO
72
+ - contentful_middleman.gemspec
73
+ - lib/contentful_middleman.rb
74
+ - lib/contentful_middleman/commands/article.tt
75
+ - lib/contentful_middleman/commands/sync_blog.rb
76
+ - lib/contentful_middleman/core.rb
77
+ - lib/contentful_middleman/version.rb
78
+ - lib/middleman_extension.rb
79
+ - spec/contentful_middleman_spec.rb
80
+ - spec/spec_helper.rb
81
+ homepage: https://www.contentful.com
82
+ licenses:
83
+ - MIT
84
+ metadata: {}
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubyforge_project:
101
+ rubygems_version: 2.0.0
102
+ signing_key:
103
+ specification_version: 4
104
+ summary: Include mangablable content from the Contentful CMS and API into your Middleman
105
+ projects
106
+ test_files:
107
+ - spec/contentful_middleman_spec.rb
108
+ - spec/spec_helper.rb