bookery 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,8 @@
1
+ .DS_Store
2
+ .bundle/
3
+ bin/*
4
+ !bin/bookery
5
+ sandbox/
6
+ vendor/
7
+ coverage/
8
+ pkg/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bookery.gemspec
4
+ gemspec
@@ -0,0 +1,64 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ bookery (0.0.1)
5
+ activesupport
6
+ i18n
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activesupport (3.2.16)
12
+ i18n (~> 0.6, >= 0.6.4)
13
+ multi_json (~> 1.0)
14
+ celluloid (0.15.2)
15
+ timers (~> 1.1.0)
16
+ coderay (1.1.0)
17
+ docile (1.1.1)
18
+ ffi (1.9.3)
19
+ formatador (0.2.4)
20
+ guard (2.2.4)
21
+ formatador (>= 0.2.4)
22
+ listen (~> 2.1)
23
+ lumberjack (~> 1.0)
24
+ pry (>= 0.9.12)
25
+ thor (>= 0.18.1)
26
+ guard-minitest (2.1.2)
27
+ guard (~> 2.0)
28
+ minitest (>= 3.0)
29
+ i18n (0.6.9)
30
+ listen (2.3.1)
31
+ celluloid (>= 0.15.2)
32
+ rb-fsevent (>= 0.9.3)
33
+ rb-inotify (>= 0.9)
34
+ lumberjack (1.0.4)
35
+ method_source (0.8.2)
36
+ minitest (5.1.0)
37
+ multi_json (1.8.2)
38
+ pry (0.9.12.4)
39
+ coderay (~> 1.0)
40
+ method_source (~> 0.8)
41
+ slop (~> 3.4)
42
+ rake (10.1.0)
43
+ rb-fsevent (0.9.3)
44
+ rb-inotify (0.9.2)
45
+ ffi (>= 0.5.0)
46
+ simplecov (0.8.2)
47
+ docile (~> 1.1.0)
48
+ multi_json
49
+ simplecov-html (~> 0.8.0)
50
+ simplecov-html (0.8.0)
51
+ slop (3.4.7)
52
+ thor (0.18.1)
53
+ timers (1.1.0)
54
+
55
+ PLATFORMS
56
+ ruby
57
+
58
+ DEPENDENCIES
59
+ bookery!
60
+ bundler (~> 1.3)
61
+ guard-minitest
62
+ minitest
63
+ rake
64
+ simplecov
@@ -0,0 +1,9 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard :minitest do
5
+ # with Minitest::Unit
6
+ watch(%r{^test/(.*)\/?(.*)_test\.rb})
7
+ watch(%r{^lib/(.*/)?([^/]+)\.rb}) { |m| "test/#{m[1]}#{m[2]}_test.rb" }
8
+ watch(%r{^test/test_helper\.rb}) { 'test' }
9
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 pseudomuto
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,19 @@
1
+ # Bookery
2
+
3
+ My own custom tool for writing books
4
+
5
+ ## Installation
6
+
7
+ $ gem install bookery
8
+
9
+ ## Usage
10
+
11
+ * `bookery new [PATH]` - create a new book
12
+
13
+ ## Contributing
14
+
15
+ 1. Fork it
16
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
17
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
18
+ 4. Push to the branch (`git push origin my-new-feature`)
19
+ 5. Create new Pull Request
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new do |t|
6
+ t.libs << 'test'
7
+ t.pattern = 'test/**/*_test.rb'
8
+ end
@@ -0,0 +1,10 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ require "pathname"
4
+ bin_file = Pathname.new(__FILE__).realpath
5
+
6
+ # add self to libpath
7
+ $:.unshift File.expand_path("../../lib", bin_file)
8
+
9
+ require 'bookery'
10
+ Bookery::CLI.start(ARGV)
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bookery/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'bookery'
8
+ spec.version = Bookery::VERSION
9
+ spec.authors = ['David Muto']
10
+ spec.email = ['david.muto@gmail.com']
11
+ spec.description = %q{A gem that gives you the tools you need to write your own book}
12
+ spec.summary = %q{A simple way to author your book}
13
+ spec.homepage = 'http://pseudomuto.com/'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'activesupport'
22
+ spec.add_dependency 'i18n'
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.3'
25
+ spec.add_development_dependency 'rake'
26
+ spec.add_development_dependency 'minitest'
27
+ spec.add_development_dependency 'guard-minitest'
28
+ spec.add_development_dependency 'simplecov'
29
+ end
@@ -0,0 +1,9 @@
1
+ require 'active_support/core_ext/string'
2
+ require 'bookery/version'
3
+ require 'bookery/chapter'
4
+ require 'bookery/book'
5
+ require 'bookery/cli'
6
+
7
+ module Bookery
8
+ # Your code goes here...
9
+ end
@@ -0,0 +1,23 @@
1
+ module Bookery
2
+ class Book
3
+ attr_reader :lang
4
+
5
+ def initialize(lang, options = {})
6
+ @lang = lang
7
+ @cwd = options[:cwd] || ''
8
+ end
9
+
10
+ def chapters
11
+ @chapters ||= Dir.entries(book_dir).collect do |entry|
12
+ Chapter.new(entry) if entry.size > 2
13
+ end.compact
14
+ end
15
+
16
+ private
17
+
18
+ def book_dir
19
+ File.join(@cwd, 'book', @lang)
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,30 @@
1
+ module Bookery
2
+ class Chapter
3
+ attr_reader :name
4
+
5
+ def initialize(chapter_dir)
6
+ @name = sanitize_name(chapter_dir)
7
+ @dir = chapter_dir
8
+ end
9
+
10
+ def markup
11
+ @markup ||= concatenate_files
12
+ end
13
+
14
+ private
15
+
16
+ def sanitize_name(path)
17
+ File.basename(path).sub(/\A\d+\s?-\s?/, '').titleize
18
+ end
19
+
20
+ def concatenate_files
21
+ contents = ''
22
+
23
+ Dir.glob(File.join(@dir, '**/*.md')) do |file|
24
+ contents << File.read(file)
25
+ end
26
+
27
+ contents
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,21 @@
1
+ require 'thor'
2
+ require 'pathname'
3
+
4
+ bin_file = Pathname.new(__FILE__).realpath
5
+
6
+ module Bookery
7
+ class CLI < Thor
8
+ include Thor::Actions
9
+
10
+ source_paths << File.expand_path(
11
+ '../../../templates',
12
+ Pathname.new(__FILE__).realpath
13
+ )
14
+
15
+ desc 'new PATH', 'creates a new book in PATH'
16
+ def new(path, template_name = 'book')
17
+ directory(template_name, path)
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ module Bookery
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems'
2
+ gem 'redcarpet'
@@ -0,0 +1,3 @@
1
+ # My Book
2
+
3
+ This is the git repository for my book...
File without changes
File without changes
@@ -0,0 +1,5 @@
1
+ book:
2
+ authors:
3
+ -
4
+ name: 'your name'
5
+ email: 'your email address'
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems'
2
+ gem 'redcarpet'
@@ -0,0 +1,3 @@
1
+ # My Book
2
+
3
+ This is the git repository for my book...
@@ -0,0 +1 @@
1
+ # The first file in chapter 2
@@ -0,0 +1 @@
1
+ # The second file in chapter 2
@@ -0,0 +1,5 @@
1
+ book:
2
+ authors:
3
+ -
4
+ name: 'your name'
5
+ email: 'your email address'
@@ -0,0 +1,19 @@
1
+ require 'test_helper'
2
+
3
+ class BookTest < AppTest
4
+ def setup
5
+ super
6
+ @book = Bookery::Book.new('en', cwd: 'sandbox')
7
+ end
8
+
9
+ def test_loads_chapters
10
+ expected_names = ['Introduction', 'Second Chapter']
11
+ actual_names = @book.chapters.map { |c| c.name }
12
+
13
+ assert_equal expected_names, actual_names
14
+ end
15
+
16
+ def template_name
17
+ 'sample'
18
+ end
19
+ end
@@ -0,0 +1,21 @@
1
+ require 'test_helper'
2
+
3
+ class ChapterTest < AppTest
4
+ def setup
5
+ super
6
+ @chapter = Bookery::Chapter.new('sandbox/book/en/02-second-chapter')
7
+ end
8
+
9
+ def test_name_is_sanitized
10
+ assert_equal 'Second Chapter', @chapter.name
11
+ end
12
+
13
+ def test_markup_contains_all_files
14
+ assert_match /# The first file in chapter 2/, @chapter.markup
15
+ assert_match /# The second file in chapter 2/, @chapter.markup
16
+ end
17
+
18
+ def template_name
19
+ 'sample'
20
+ end
21
+ end
@@ -0,0 +1,28 @@
1
+ require 'test_helper'
2
+
3
+ class CLITest < AppTest
4
+
5
+ def test_new_creates_readme_file
6
+ assert_file 'README.md'
7
+ end
8
+
9
+ def test_new_creates_gemfile
10
+ assert_file 'Gemfile'
11
+ end
12
+
13
+ def test_new_creates_book_folder
14
+ assert_dir 'book'
15
+ end
16
+
17
+ def test_new_creates_en_folder_in_book
18
+ assert_dir 'book/en'
19
+ end
20
+
21
+ def test_new_creates_assets_folder
22
+ assert_dir 'assets'
23
+ end
24
+
25
+ def test_new_creates_config_yml
26
+ assert_file 'config.yml'
27
+ end
28
+ end
@@ -0,0 +1,54 @@
1
+ require 'simplecov'
2
+ SimpleCov.start do
3
+ add_filter "/vendor/"
4
+ end
5
+
6
+ require 'minitest/autorun'
7
+ require 'minitest/pride'
8
+ require File.expand_path('../../lib/bookery', __FILE__)
9
+
10
+ require 'stringio'
11
+
12
+ def capture(stream)
13
+ begin
14
+ stream = stream.to_s
15
+ eval "$#{stream} = StringIO.new"
16
+ yield
17
+ result = eval("$#{stream}").string
18
+ ensure
19
+ eval("$#{stream} = #{stream.upcase}")
20
+ end
21
+
22
+ result
23
+ end
24
+
25
+ alias :silence :capture
26
+
27
+ class AppTest < MiniTest::Unit::TestCase
28
+ def template_name
29
+ 'book'
30
+ end
31
+
32
+ def setup
33
+ silence(:stdout) do
34
+ args = ['new', destination_root, template_name]
35
+ Bookery::CLI.start(args)
36
+ end
37
+ end
38
+
39
+ def teardown
40
+ ::FileUtils.rm_rf(destination_root)
41
+ end
42
+
43
+ def destination_root
44
+ 'sandbox'
45
+ end
46
+
47
+ def assert_file(relative_path)
48
+ assert File.exist?(File.join(destination_root, relative_path))
49
+ end
50
+
51
+ def assert_dir(relative_path)
52
+ assert File.directory?(File.join(destination_root, relative_path))
53
+ end
54
+ end
metadata ADDED
@@ -0,0 +1,199 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bookery
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - David Muto
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-12-08 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activesupport
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: i18n
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: bundler
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '1.3'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: minitest
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: guard-minitest
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: simplecov
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
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
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ description: A gem that gives you the tools you need to write your own book
127
+ email:
128
+ - david.muto@gmail.com
129
+ executables:
130
+ - bookery
131
+ extensions: []
132
+ extra_rdoc_files: []
133
+ files:
134
+ - .gitignore
135
+ - Gemfile
136
+ - Gemfile.lock
137
+ - Guardfile
138
+ - LICENSE.txt
139
+ - README.md
140
+ - Rakefile
141
+ - bin/bookery
142
+ - bookery.gemspec
143
+ - lib/bookery.rb
144
+ - lib/bookery/book.rb
145
+ - lib/bookery/chapter.rb
146
+ - lib/bookery/cli.rb
147
+ - lib/bookery/version.rb
148
+ - templates/book/Gemfile
149
+ - templates/book/README.md
150
+ - templates/book/assets/.empty_directory
151
+ - templates/book/book/.empty_directory
152
+ - templates/book/book/en/.empty_directory
153
+ - templates/book/config.yml
154
+ - templates/sample/Gemfile
155
+ - templates/sample/README.md
156
+ - templates/sample/book/en/01-introduction/01-intro-to-book.md
157
+ - templates/sample/book/en/02-second-chapter/01-first-things-first.md
158
+ - templates/sample/book/en/02-second-chapter/02-before_intro.md
159
+ - templates/sample/config.yml
160
+ - test/bookery/book_test.rb
161
+ - test/bookery/chapter_test.rb
162
+ - test/bookery/cli_test.rb
163
+ - test/test_helper.rb
164
+ homepage: http://pseudomuto.com/
165
+ licenses:
166
+ - MIT
167
+ post_install_message:
168
+ rdoc_options: []
169
+ require_paths:
170
+ - lib
171
+ required_ruby_version: !ruby/object:Gem::Requirement
172
+ none: false
173
+ requirements:
174
+ - - ! '>='
175
+ - !ruby/object:Gem::Version
176
+ version: '0'
177
+ segments:
178
+ - 0
179
+ hash: -4520270843693735854
180
+ required_rubygems_version: !ruby/object:Gem::Requirement
181
+ none: false
182
+ requirements:
183
+ - - ! '>='
184
+ - !ruby/object:Gem::Version
185
+ version: '0'
186
+ segments:
187
+ - 0
188
+ hash: -4520270843693735854
189
+ requirements: []
190
+ rubyforge_project:
191
+ rubygems_version: 1.8.23
192
+ signing_key:
193
+ specification_version: 3
194
+ summary: A simple way to author your book
195
+ test_files:
196
+ - test/bookery/book_test.rb
197
+ - test/bookery/chapter_test.rb
198
+ - test/bookery/cli_test.rb
199
+ - test/test_helper.rb