qiita-build 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: 02510d5cf8aa538ae3201949cc6a72ceeeaf536e
4
+ data.tar.gz: 97a4b0f00d40e66f20bf8d155ddb968955c61fa9
5
+ SHA512:
6
+ metadata.gz: c867f39ab7d82abc996bca52a1ea9fa69018cb358caa3325659d67829184ad32dd0d59aeb6e74315b1c4579f0746be2e56d7496a90425c2e3476db8bcd4c8cd5
7
+ data.tar.gz: ce85abf2560c557eb02678b8bf43932b3d8a624e7d22b405983fb7341b1033c91cf70354e79ac006bcf9581d93e575aa07ca163d25c66003cb721d228bf46383
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in qiita-build.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Naoto Kaneko
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,40 @@
1
+ # qiita-build
2
+
3
+ Qiita item builder from a template and stdin
4
+
5
+ ## Installation
6
+
7
+ ```
8
+ $ gem install qiita-build
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ Given a below template,
14
+
15
+ ```
16
+ # 自己紹介
17
+ * 氏名: %{fullname}
18
+ * ニックネーム: %{nickname}
19
+ * 居住地: %{location}
20
+ * 生年月日: %{birthday}
21
+ ```
22
+
23
+ `qiita-build` will build an item from the template and stdin, like this.
24
+
25
+ ```
26
+ $ echo '{"fullname": "Naoto Kanekoo", "nickname": "naoty", "location": "Tokyo", "birthday": "1987/6/2"}' | qiita-build -a <ACCESS TOKEN> -t <TEAM> <TEMPLATE ID>
27
+ # 自己紹介
28
+ * 氏名: Naoto Kaneko
29
+ * ニックネーム: naoty
30
+ * 居住地: Tokyo
31
+ * 生年月日: 1987/6/2
32
+ ```
33
+
34
+ ## Contributing
35
+
36
+ 1. Fork it ( https://github.com/[my-github-username]/qiita-build/fork )
37
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
38
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
39
+ 4. Push to the branch (`git push origin my-new-feature`)
40
+ 5. Create a new Pull Request
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
7
+
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ lib = File.expand_path("../lib", __dir__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+
6
+ require "qiita-build"
7
+
8
+ stdin = STDIN.gets
9
+ command = Qiita::Build::Command.new(stdin, ARGV)
10
+ command.run
@@ -0,0 +1,3 @@
1
+ require "qiita/build/builder"
2
+ require "qiita/build/command"
3
+ require "qiita/build/version"
@@ -0,0 +1,15 @@
1
+ module Qiita
2
+ module Build
3
+ class Builder
4
+ def initialize
5
+ end
6
+
7
+ def build(template: "", json: {})
8
+ json.each do |key, value|
9
+ template.gsub!(%r{%\{#{key.to_s}\}}) { value }
10
+ end
11
+ template
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,49 @@
1
+ require "json"
2
+ require "optparse"
3
+ require "qiita"
4
+
5
+ module Qiita
6
+ module Build
7
+ class Command
8
+ def initialize(stdin, argv)
9
+ @options = {}
10
+ @json = JSON.parse(stdin)
11
+ @argv = parse_options!(argv)
12
+ end
13
+
14
+ def run
15
+ client = Qiita::Client.new(team: team, access_token: access_token)
16
+ response = client.get_template(template_id)
17
+ template = response.body["body"]
18
+ puts Builder.new.build(template: template, json: @json)
19
+ end
20
+
21
+ private
22
+
23
+ def parse_options!(options)
24
+ option_parser.on("-a VAL", "--access-token=VAL") { |v| @options[:access_token] = v }
25
+ option_parser.on("-t VAL", "--team=VAL") { |v| @options[:team] = v }
26
+ argv = option_parser.parse!(options)
27
+ argv.delete(access_token)
28
+ argv.delete(team)
29
+ argv
30
+ end
31
+
32
+ def option_parser
33
+ @option_parser ||= OptionParser.new
34
+ end
35
+
36
+ def access_token
37
+ @options[:access_token]
38
+ end
39
+
40
+ def team
41
+ @options[:team]
42
+ end
43
+
44
+ def template_id
45
+ @template_id ||= @argv.pop
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,5 @@
1
+ module Qiita
2
+ module Build
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "qiita/build/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "qiita-build"
8
+ spec.version = Qiita::Build::VERSION
9
+ spec.authors = ["Naoto Kaneko"]
10
+ spec.email = ["naoty.k@gmail.com"]
11
+ spec.summary = %q{Qiita item builder from a template and stdin}
12
+ spec.homepage = "https://github.com/naoty/qiita-build"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
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 "qiita"
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.7"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec"
25
+ spec.add_development_dependency "pry"
26
+ end
@@ -0,0 +1,5 @@
1
+ # 自己紹介
2
+ * 氏名: Naoto Kaneko
3
+ * ニックネーム: naoty
4
+ * 居住地: Tokyo
5
+ * 生年月日: 1987/6/2
@@ -0,0 +1,5 @@
1
+ # 自己紹介
2
+ * 氏名: %{fullname}
3
+ * ニックネーム: %{nickname}
4
+ * 居住地: %{location}
5
+ * 生年月日: %{birthday}
@@ -0,0 +1,37 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe Qiita::Build::Builder do
4
+ let(:fixture_path) do
5
+ path = File.expand_path("../../fixtures", __dir__)
6
+ Pathname.new(path)
7
+ end
8
+
9
+ let(:builder) do
10
+ described_class.new
11
+ end
12
+
13
+ describe "#build" do
14
+ let(:template) do
15
+ fixture_path.join("template.md").read
16
+ end
17
+
18
+ let(:item) do
19
+ fixture_path.join("item.md").read
20
+ end
21
+
22
+ let(:json) do
23
+ {
24
+ fullname: "Naoto Kaneko",
25
+ nickname: "naoty",
26
+ location: "Tokyo",
27
+ birthday: "1987/6/2"
28
+ }
29
+ end
30
+
31
+ subject do
32
+ builder.build(template: template, json: json)
33
+ end
34
+
35
+ it { is_expected.to eq item }
36
+ end
37
+ end
@@ -0,0 +1,4 @@
1
+ lib = File.expand_path("../lib", __dir__)
2
+ $LOAD_PATH.unshift lib unless $LOAD_PATH.include?(lib)
3
+ require "qiita-build"
4
+ require "pathname"
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: qiita-build
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Naoto Kaneko
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: qiita
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
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
+ description:
84
+ email:
85
+ - naoty.k@gmail.com
86
+ executables:
87
+ - qiita-build
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".travis.yml"
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - bin/qiita-build
99
+ - lib/qiita-build.rb
100
+ - lib/qiita/build/builder.rb
101
+ - lib/qiita/build/command.rb
102
+ - lib/qiita/build/version.rb
103
+ - qiita-build.gemspec
104
+ - spec/fixtures/item.md
105
+ - spec/fixtures/template.md
106
+ - spec/qiita/build/builder_spec.rb
107
+ - spec/spec_helper.rb
108
+ homepage: https://github.com/naoty/qiita-build
109
+ licenses:
110
+ - MIT
111
+ metadata: {}
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubyforge_project:
128
+ rubygems_version: 2.4.5
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: Qiita item builder from a template and stdin
132
+ test_files:
133
+ - spec/fixtures/item.md
134
+ - spec/fixtures/template.md
135
+ - spec/qiita/build/builder_spec.rb
136
+ - spec/spec_helper.rb