batch_it 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 64d2c4ed0908103fe47b936113fc971caac3d32d
4
+ data.tar.gz: 5d27a799ca07acba7f01c251f7f620d34d634919
5
+ SHA512:
6
+ metadata.gz: c85988671443a23c7ac95e7bb39959c00bab071584ef4fa9cf990f99ac97a6f80b4864902a30d22bd4b0fd482cdf6f6704c7ba6519eb4b8599aefd963be1a1bb
7
+ data.tar.gz: ec2198a3e9b2abe017d682980fe4c060709e35586c2d5a7c83c467d0febf2d67282e848906addf210ac7a53439ae1bafd6ed08a9d5c252bf9a49d1687f9dc18f
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1 @@
1
+ SimpleCov.start
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in batch_it.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Caleb Buxton
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,37 @@
1
+ # BatchIt
2
+
3
+ Quick and dirty (possibly batch) processing of .markdown.erb files.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'batch_it'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install batch_it
18
+
19
+ ## Usage
20
+
21
+ ```ruby
22
+ require 'batch_it'
23
+ require 'ostruct'
24
+
25
+ puts BatchIt.new(DATA.read).result([OpenStruct.new(title: "One"), OpenStruct.new(title: "Two")])
26
+ __END__
27
+ <%= title %>
28
+ =
29
+ ```
30
+
31
+ ## Contributing
32
+
33
+ 1. Fork it
34
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
35
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
36
+ 4. Push to the branch (`git push origin my-new-feature`)
37
+ 5. Create new Pull Request
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "batch_it"
7
+ spec.version = File.read(File.join(File.dirname(__FILE__),"VERSION"))
8
+ spec.authors = ["Caleb Buxton"]
9
+ spec.email = ["me@cpb.ca"]
10
+ spec.description = %q{Batch process your erb markdown}
11
+ spec.summary = %q{Batch process your erb markdown}
12
+ spec.homepage = "http://github.com/cpb/batch_it"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "tilt", "~> 2.0"
21
+ spec.add_dependency "redcarpet", "~> 3.0"
22
+ spec.add_development_dependency "aruba"
23
+ spec.add_development_dependency "bundler", "~> 1.3"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "rspec", "~> 3.0.0.beta1"
26
+ spec.add_development_dependency "pry"
27
+ spec.add_development_dependency "simplecov"
28
+ end
@@ -0,0 +1,25 @@
1
+ Feature: The public interface documented in the README
2
+
3
+ @disable-bundler
4
+ Scenario: First installation using Bundler
5
+ Given a file named "Gemfile" with:
6
+ """
7
+ gem "batch_it", path: "../../"
8
+ """
9
+ And a file named "example.rb" with:
10
+ """
11
+ require 'batch_it'
12
+ require 'ostruct'
13
+
14
+ puts BatchIt.new(DATA.read).result([OpenStruct.new(title: "One"), OpenStruct.new(title: "Two")])
15
+ __END__
16
+ <%= title %>
17
+ =
18
+ """
19
+ And I run `bundle install > /dev/null`
20
+ When I successfully run `bundle exec ruby example.rb` for up to 6 seconds
21
+ Then the output should contain:
22
+ """
23
+ <h1>One</h1>
24
+ <h1>Two</h1>
25
+ """
@@ -0,0 +1 @@
1
+ require 'aruba/cucumber'
@@ -0,0 +1,45 @@
1
+ require 'tilt'
2
+
3
+ class BatchIt
4
+ VERSION = File.read(File.join(File.dirname(__FILE__),"..","VERSION")).freeze
5
+
6
+ attr_reader :corpus
7
+ def initialize(corpus)
8
+ @corpus = corpus
9
+ @erb_template, @markdown_template = Tilt.templates_for("corpus.markdown.erb")
10
+ end
11
+
12
+ def result(data)
13
+ enumerate_over_bindings(data) do |bind|
14
+ markdown_result(erb_result(corpus, bind))
15
+ end
16
+ end
17
+
18
+ private
19
+ def enumerate_over_bindings(input)
20
+ case input
21
+ when Array
22
+ input.map do |item|
23
+ yield(item)
24
+ end
25
+ else
26
+ yield(input)
27
+ end
28
+ end
29
+
30
+ def markdown_template(corpus)
31
+ @markdown_template.new{corpus}
32
+ end
33
+
34
+ def markdown_result(corpus)
35
+ markdown_template(corpus).render
36
+ end
37
+
38
+ def erb_result(corpus, data)
39
+ erb(corpus).render(data)
40
+ end
41
+
42
+ def erb(corpus)
43
+ @erb ||= @erb_template.new("corpus.erb", trim: false) { corpus }
44
+ end
45
+ end
@@ -0,0 +1,57 @@
1
+ require 'spec_helper'
2
+
3
+ describe BatchIt do
4
+ it 'should have a version number' do
5
+ expect(BatchIt::VERSION).to_not be_nil
6
+ end
7
+
8
+ context "with some markdown" do
9
+ let(:markdown) do
10
+ File.read(__FILE__).split(/^__END__$/,2).last
11
+ end
12
+
13
+ let(:batch_it) { described_class.new(markdown) }
14
+
15
+ context "#result with a scalar" do
16
+ let(:scalar) { double(title: "The Title", subtitle: "Nonsense", quote: "Emergency Solution") }
17
+
18
+ subject { batch_it.result(scalar) }
19
+
20
+ it "should have the title in an h1" do
21
+ expect(subject).to include("<h1>The Title</h1>")
22
+ end
23
+
24
+ it "should have the subtitle in an h2" do
25
+ expect(subject).to include("<h2>Nonsense</h2>")
26
+ end
27
+
28
+ it "should have the quote" do
29
+ expect(subject).to include("<p>Emergency Solution</p>")
30
+ end
31
+ end
32
+
33
+ context "#result with an enumerable" do
34
+ let(:enumerable) { [double(title: "The Title", subtitle: "Nonsense", quote: "Emergency Solution"), double(title: "The Title 2", subtitle: "Nonsense 2", quote: "Emergency Solution 2")]}
35
+
36
+ subject { batch_it.result(enumerable) }
37
+
38
+ it "should have as many items as in the enumerable" do
39
+ expect(subject.length).to eql(enumerable.length)
40
+ end
41
+
42
+ it "should render the corpus for each element" do
43
+ expect(subject.first).to include("<h1>The Title</h1>")
44
+ expect(subject.last).to include("<h1>The Title 2</h1>")
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+ __END__
51
+ <%= title %>
52
+ =
53
+
54
+ <%= subtitle %>
55
+ -
56
+
57
+ > <%= quote %>
@@ -0,0 +1,5 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'pry'
3
+
4
+ require 'simplecov'
5
+ require 'batch_it'
metadata ADDED
@@ -0,0 +1,175 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: batch_it
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Caleb Buxton
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: tilt
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: redcarpet
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: aruba
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '1.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: 3.0.0.beta1
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: 3.0.0.beta1
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: Batch process your erb markdown
126
+ email:
127
+ - me@cpb.ca
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - .gitignore
133
+ - .rspec
134
+ - .simplecov
135
+ - .travis.yml
136
+ - Gemfile
137
+ - LICENSE.txt
138
+ - README.md
139
+ - Rakefile
140
+ - VERSION
141
+ - batch_it.gemspec
142
+ - features/README.md.feature
143
+ - features/support/env.rb
144
+ - lib/batch_it.rb
145
+ - spec/batch_it_spec.rb
146
+ - spec/spec_helper.rb
147
+ homepage: http://github.com/cpb/batch_it
148
+ licenses:
149
+ - MIT
150
+ metadata: {}
151
+ post_install_message:
152
+ rdoc_options: []
153
+ require_paths:
154
+ - lib
155
+ required_ruby_version: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - '>='
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ required_rubygems_version: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - '>='
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
165
+ requirements: []
166
+ rubyforge_project:
167
+ rubygems_version: 2.0.3
168
+ signing_key:
169
+ specification_version: 4
170
+ summary: Batch process your erb markdown
171
+ test_files:
172
+ - features/README.md.feature
173
+ - features/support/env.rb
174
+ - spec/batch_it_spec.rb
175
+ - spec/spec_helper.rb