middleman-tapirgo 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,18 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in middleman-deploy.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem "rake", "~> 0.9.2"
8
+ gem "rdoc", "~> 3.9"
9
+ gem "yard", "~> 0.8.0"
10
+ end
11
+
12
+ group :test do
13
+ gem "cucumber", "~> 1.2.0"
14
+ gem "fivemat"
15
+ gem "aruba", "~> 0.4.11"
16
+ gem "rspec", "~> 2.7"
17
+ gem "simplecov"
18
+ end
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Robert Beekman (@matsimitsu)
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 included
12
+ 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 NONINFRINGEMENT.
17
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ Middleman TapirGo - Sync generated content from [middleman](http://middlemanapp.com/) to [TapirGo](http://tapirgo.com)
2
+
3
+
4
+ # QUICK START
5
+
6
+ ## Step 1
7
+
8
+ Edit `Gemfile`, and add:
9
+
10
+ gem "middleman-tapirgo"
11
+
12
+ Then run:
13
+
14
+ bundle install
15
+
16
+ ## Step 2 - setup
17
+
18
+ **These settings are required.**
19
+
20
+ Edit `config.rb`, and add:
21
+
22
+ activate :tapirgo do |tapir|
23
+ tapir.api_key = "[Your tapirgo api key]"
24
+ end
25
+
26
+ ## Step 3
27
+
28
+ Run middleman build, after compiling your site, your content will be
29
+ pushed to TapirGo
30
+
31
+ middleman build
32
+
33
+ ## Thanks
34
+
35
+ Based on the middleman-deploy gem by
36
+ [Tom Vaughan](https://github.com/tvaughan/middleman-deploy).
data/Rakefile ADDED
@@ -0,0 +1,26 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ task :test => ['rspec']
5
+ require "middleman-tapirgo/pkg-info"
6
+
7
+ PACKAGE = "#{Middleman::Tapirgo::PACKAGE}"
8
+ VERSION = "#{Middleman::Tapirgo::VERSION}"
9
+
10
+ task :package do
11
+ system "gem build #{PACKAGE}.gemspec"
12
+ end
13
+
14
+ task :install => :package do
15
+ Dir.chdir("pkg") do
16
+ system "gem install #{PACKAGE}-#{VERSION}"
17
+ end
18
+ end
19
+
20
+ task :release => :package do
21
+ Dir.chdir("pkg") do
22
+ system "gem push #{PACKAGE}-#{VERSION}"
23
+ end
24
+ end
25
+
26
+ task :default => :test
@@ -0,0 +1,42 @@
1
+ # Require core library
2
+ require "middleman-core"
3
+
4
+ # Extension namespace
5
+ module Middleman
6
+ module Tapirgo
7
+
8
+ class Options < Struct.new(:api_key); end
9
+
10
+ class << self
11
+
12
+ def options
13
+ @@options
14
+ end
15
+
16
+ def registered(app, options_hash={}, &block)
17
+ options = Options.new(options_hash)
18
+ yield options if block_given?
19
+
20
+ options.api_key ||= nil
21
+
22
+ app.after_build do |builder|
23
+ ::Middleman::Tapirgo::Syncer.new(options).sync
24
+ end
25
+
26
+ @@options = options
27
+
28
+ app.send :include, Helpers
29
+ end
30
+
31
+ alias :included :registered
32
+
33
+ end
34
+
35
+ module Helpers
36
+ def options
37
+ ::Middleman::Tapirgo.options
38
+ end
39
+ end
40
+
41
+ end
42
+ end
@@ -0,0 +1,6 @@
1
+ module Middleman
2
+ module Tapirgo
3
+ PACKAGE = "middleman-tapirgo"
4
+ VERSION = "0.0.1"
5
+ end
6
+ end
@@ -0,0 +1,39 @@
1
+ module Middleman
2
+ module Tapirgo
3
+
4
+ class SyncableItem
5
+
6
+ def initialize(resource)
7
+ @resource = resource
8
+ end
9
+
10
+ def content
11
+ @resource.render(:layout => nil)
12
+ end
13
+
14
+ def published_on
15
+ Time.parse(@resource.data['date'])
16
+ rescue
17
+ File.mtime(@resource.source_file)
18
+ end
19
+
20
+ def title
21
+ @resource.data['title'] || @resource.path
22
+ end
23
+
24
+ def link
25
+ @resource.path
26
+ end
27
+
28
+ def to_hash
29
+ {
30
+ :title => title,
31
+ :content => content,
32
+ :link => link,
33
+ :published_on => published_on
34
+ }
35
+ end
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,46 @@
1
+ module Middleman
2
+ module Tapirgo
3
+
4
+ class Syncer
5
+
6
+ attr_reader :options
7
+ def initialize(options={})
8
+ @options = options
9
+ end
10
+
11
+ def inst
12
+ ::Middleman::Application.server.inst
13
+ end
14
+
15
+ def uri
16
+ URI("http://tapirgo.com/api/1/push_article.json?secret=#{options[:api_key]}")
17
+ end
18
+
19
+ def syncable_items
20
+ @syncable_items ||= inst.sitemap.resources.select { |r| r.ext == '.html' }
21
+ end
22
+
23
+ def sync
24
+ return unless options[:api_key]
25
+
26
+ syncable_items.each do |r|
27
+ syncable_item = Middleman::Tapirgo::SyncableItem.new(r)
28
+ response = send_to_tapirgo(syncable_item)
29
+ if response.code != '200'
30
+ puts "Failed sending #{syncable_item.link} to TapirGo"
31
+ puts "Response #{response.code} #{response.message}"
32
+ break
33
+ end
34
+ end
35
+ puts "Synced #{syncable_items.length} items to TapirGo"
36
+ end
37
+
38
+ def send_to_tapirgo(item)
39
+ req = Net::HTTP::Post.new(uri.path, initheader = {'Content-Type' =>'application/json'})
40
+ req.body = JSON.generate(item)
41
+ Net::HTTP.new(uri.host, uri.port).start {|http| http.request(req) }
42
+ end
43
+ end
44
+
45
+ end
46
+ end
@@ -0,0 +1,8 @@
1
+ require "middleman-core"
2
+ require "middleman-tapirgo/syncer"
3
+ require "middleman-tapirgo/syncable_item"
4
+
5
+ ::Middleman::Extensions.register(:tapirgo) do
6
+ require "middleman-tapirgo/extension"
7
+ ::Middleman::Tapirgo
8
+ end
@@ -0,0 +1 @@
1
+ require "middleman-tapirgo"
@@ -0,0 +1,31 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "middleman-tapirgo/pkg-info"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = Middleman::Tapirgo::PACKAGE
7
+ s.version = Middleman::Tapirgo::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Robert Beekman"]
10
+ s.email = ["robert@matsimitsu.nl"]
11
+ s.homepage = "http://github.com/matsimitsu/middleman-tapirgo/"
12
+ s.summary = %q{Sync middleman content to TapirGO}
13
+ s.description = %q{Sync middleman content to TapirGO}
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_runtime_dependency("middleman-core", [">= 3.0.0"])
23
+
24
+ # Additional dependencies
25
+ s.add_runtime_dependency("json")
26
+
27
+ # Test dependencies
28
+ s.add_development_dependency 'rspec'
29
+ s.add_development_dependency 'webmock'
30
+
31
+ end
@@ -0,0 +1,79 @@
1
+ require 'spec_helper'
2
+
3
+ describe Middleman::Tapirgo::SyncableItem do
4
+
5
+ let(:resource) do
6
+ mock(
7
+ :render => 'story about moo',
8
+ :data => {
9
+ 'date' => '01-01-2001 10:00:00 UTC',
10
+ 'title' => 'moo'
11
+ },
12
+ :path => 'index.html',
13
+ :source_file => '/resources/index.html'
14
+ )
15
+ end
16
+ let(:syncable_item) { Middleman::Tapirgo::SyncableItem.new(resource) }
17
+
18
+ describe "#content" do
19
+
20
+ it "should call render on the resource" do
21
+ resource.should_receive(:render).with(:layout => nil)
22
+ end
23
+
24
+ after { syncable_item.content }
25
+ end
26
+
27
+ describe "#published_on" do
28
+ subject { syncable_item.published_on }
29
+
30
+ it { should == Time.parse('01-01-2001 10:00:00 UTC') }
31
+
32
+ context "when data['time'] is missing" do
33
+ let(:resource) do
34
+ mock(
35
+ :data => {},
36
+ :source_file => '/resources/index.html'
37
+ )
38
+ end
39
+
40
+ it "sould call File.mtime" do
41
+ File.should_receive(:mtime).with('/resources/index.html')
42
+ end
43
+
44
+ after { syncable_item.published_on }
45
+ end
46
+ end
47
+
48
+ describe "#title"do
49
+ subject { syncable_item.title }
50
+
51
+ it { should == 'moo' }
52
+
53
+ context "without title in the data" do
54
+ let(:resource) { mock(:data => {}, :path => 'index.html') }
55
+
56
+ it { should == 'index.html' }
57
+ end
58
+ end
59
+
60
+ describe "#link" do
61
+ subject { syncable_item.link }
62
+
63
+ it { should == 'index.html' }
64
+ end
65
+
66
+ describe "#to_hash" do
67
+ subject { syncable_item.to_hash }
68
+
69
+ it "should return a TapirGo compatible hash" do
70
+ should == {
71
+ :title => 'moo',
72
+ :content => 'story about moo',
73
+ :link => 'index.html',
74
+ :published_on => Time.parse('01-01-2001 10:00:00 UTC')
75
+ }
76
+ end
77
+ end
78
+
79
+ end
@@ -0,0 +1,123 @@
1
+ require 'spec_helper'
2
+
3
+ describe Middleman::Tapirgo::Syncer do
4
+
5
+ let(:syncer) { Middleman::Tapirgo::Syncer.new(:api_key => 'bananas') }
6
+ before { syncer.stub(:puts => true) }
7
+
8
+ describe "#inst" do
9
+ subject { syncer.inst.class.name }
10
+
11
+ it "should return an instance of middleman" do
12
+ should == 'Middleman::Application::MiddlemanApplication1'
13
+ end
14
+ end
15
+
16
+ describe "#options" do
17
+ subject { syncer.options }
18
+
19
+ it "should return a hash with the options" do
20
+ should == { :api_key => 'bananas' }
21
+ end
22
+ end
23
+
24
+ describe "#uri" do
25
+ subject { syncer.uri.to_s }
26
+
27
+ it "should return the correct URI" do
28
+ should == "http://tapirgo.com/api/1/push_article.json?secret=bananas"
29
+ end
30
+ end
31
+
32
+ describe "#syncable_items" do
33
+ let(:resources) { [mock(:ext => '.html'), mock(:ext => '.css')] }
34
+
35
+ before do
36
+ syncer.stub_chain(:inst, :sitemap, :resources => resources)
37
+ end
38
+ subject { syncer.syncable_items }
39
+
40
+ it "should return an array with html files from the sitemap" do
41
+ should == [resources.first]
42
+ end
43
+ end
44
+
45
+ describe "sync" do
46
+ let(:resource) { mock(:ext => '.html') }
47
+ let(:syncable_item) { mock(:to_hash => {'a' => 'b'}, :link => 'index.html') }
48
+ let(:response) { mock(:code => '200') }
49
+ before do
50
+ Middleman::Tapirgo::SyncableItem.stub(:new => syncable_item)
51
+ syncer.stub(
52
+ :syncable_items => [resource],
53
+ :send_to_tapirgo => response
54
+ )
55
+ end
56
+
57
+ describe "with api key" do
58
+
59
+ it "should get a new syncable item" do
60
+ Middleman::Tapirgo::SyncableItem.
61
+ should_receive(:new).
62
+ with(resource)
63
+ end
64
+
65
+ it "should send the item to tapirgo" do
66
+ syncer.should_receive(:send_to_tapirgo).with(syncable_item)
67
+ end
68
+
69
+ context "when the respone code is not 200: OK" do
70
+ before { response.stub(:code => '404', :message => 'not found') }
71
+
72
+ it "should puts a message telling the user" do
73
+ syncer.
74
+ should_receive(:puts).
75
+ with('Failed sending index.html to TapirGo')
76
+
77
+ syncer.
78
+ should_receive(:puts).
79
+ with('Response 404 not found')
80
+ end
81
+ end
82
+
83
+ after { syncer.sync }
84
+ end
85
+
86
+ context "without api_key" do
87
+ let(:syncer_without_api_key) do
88
+ Middleman::Tapirgo::Syncer.new
89
+ end
90
+
91
+ it "should not call syncable items" do
92
+ syncer_without_api_key.should_not_receive(:syncable_items)
93
+ end
94
+
95
+ after { syncer_without_api_key.sync }
96
+ end
97
+ end
98
+
99
+ describe "#send_to_tapirgo" do
100
+ let(:item) { mock(:to_hash => {'a' => 'b'}) }
101
+ before do
102
+ stub_request(:post, "http://tapirgo.com/api/1/push_article.json").
103
+ with(:body => "{\"a\":\"b\"}",
104
+ :headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json'}).
105
+ to_return(:status => 200, :body => "", :headers => {})
106
+
107
+ syncer.send_to_tapirgo(item)
108
+ end
109
+
110
+ it "should post the item to tapirgo" do
111
+ WebMock.should have_requested(
112
+ :post, "http://tapirgo.com/api/1/push_article.json"
113
+ ).with(
114
+ :body => "{\"a\":\"b\"}",
115
+ :headers => {
116
+ 'Accept' => '*/*',
117
+ 'Content-Type' => 'application/json'
118
+ }
119
+ ).once
120
+ end
121
+ end
122
+
123
+ end
@@ -0,0 +1,2 @@
1
+ <h1>Woo</h1>
2
+ <p>moo</p>
@@ -0,0 +1,6 @@
1
+ require 'rspec'
2
+ require 'webmock/rspec'
3
+ require 'middleman-tapirgo'
4
+
5
+ RSpec.configure do |config|
6
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: middleman-tapirgo
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Robert Beekman
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2013-06-08 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: middleman-core
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 3
29
+ - 0
30
+ - 0
31
+ version: 3.0.0
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: json
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ version: "0"
44
+ type: :runtime
45
+ version_requirements: *id002
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ prerelease: false
49
+ requirement: &id003 !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ segments:
54
+ - 0
55
+ version: "0"
56
+ type: :development
57
+ version_requirements: *id003
58
+ - !ruby/object:Gem::Dependency
59
+ name: webmock
60
+ prerelease: false
61
+ requirement: &id004 !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ segments:
66
+ - 0
67
+ version: "0"
68
+ type: :development
69
+ version_requirements: *id004
70
+ description: Sync middleman content to TapirGO
71
+ email:
72
+ - robert@matsimitsu.nl
73
+ executables: []
74
+
75
+ extensions: []
76
+
77
+ extra_rdoc_files: []
78
+
79
+ files:
80
+ - .gitignore
81
+ - Gemfile
82
+ - LICENSE
83
+ - README.md
84
+ - Rakefile
85
+ - lib/middleman-tapirgo.rb
86
+ - lib/middleman-tapirgo/extension.rb
87
+ - lib/middleman-tapirgo/pkg-info.rb
88
+ - lib/middleman-tapirgo/syncable_item.rb
89
+ - lib/middleman-tapirgo/syncer.rb
90
+ - lib/middleman_extension.rb
91
+ - middleman-tapirgo.gemspec
92
+ - spec/lib/middleman-tapirgo/syncable_item_spec.rb
93
+ - spec/lib/middleman-tapirgo/syncer_spec.rb
94
+ - spec/resources/index.html
95
+ - spec/spec_helper.rb
96
+ has_rdoc: true
97
+ homepage: http://github.com/matsimitsu/middleman-tapirgo/
98
+ licenses:
99
+ - MIT
100
+ post_install_message:
101
+ rdoc_options: []
102
+
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ segments:
110
+ - 0
111
+ version: "0"
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ segments:
117
+ - 0
118
+ version: "0"
119
+ requirements: []
120
+
121
+ rubyforge_project:
122
+ rubygems_version: 1.3.6
123
+ signing_key:
124
+ specification_version: 3
125
+ summary: Sync middleman content to TapirGO
126
+ test_files:
127
+ - spec/lib/middleman-tapirgo/syncable_item_spec.rb
128
+ - spec/lib/middleman-tapirgo/syncer_spec.rb
129
+ - spec/resources/index.html
130
+ - spec/spec_helper.rb