softcover 1.0.beta1 → 1.0.beta2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 07316c46b4a5618e9456de93af46e5bbb111ba9c
4
- data.tar.gz: 915b545aaa9fdaf36207fb95d8a7671d8627939c
3
+ metadata.gz: 9ccab0f06964521c03fd7c56a996de31eabd757b
4
+ data.tar.gz: 643ddcb936aa0f665b58427f0be674872e411a9f
5
5
  SHA512:
6
- metadata.gz: f02e3ee81191ad6d8731df6c1bcd6a94c134a7e0595a1039671e0f94bb2158dd581fa606127324e08db7a9c9e9fbfb2ad6cf64d4e2c3f172b580b23b97b780d8
7
- data.tar.gz: d0770ea2d5d9c20f45ca27fef220431ea7f489b59976d1a4b1ef23557ae2a327856902aba861b7fcfe3e643920e51766f200c43ea757ef5f8c6fadda3689405f
6
+ metadata.gz: 2e23b52f39af0eee6b25bb2f6d7c45b9dc46ac492cc68234385dba25716df4731caea95ed49c0a4138532ea5d6d28a95a43006f0509962af06f63f8d3a0a17ef
7
+ data.tar.gz: 77452de4891b2a2df57c256030c224248a50d8d33d4626ade977658c6322ace645617b7ebf7c902df891a5a6a79fcf7bdcdbe44997ad6dc88a582eb1150825da
@@ -93,25 +93,29 @@ class Softcover::Book
93
93
  end
94
94
  end
95
95
 
96
- def create_or_update
96
+ def create_or_update(options={})
97
97
  raise "HTML not built!" if Dir['html/*'].empty?
98
98
 
99
- res = @client.create_or_update_book id: id,
100
- files: files,
101
- title: title,
102
- slug: slug,
103
- subtitle: subtitle,
104
- description: description,
105
- chapters: chapter_attributes,
106
- prices: prices,
107
- faq: faq,
108
- testimonials: testimonials,
109
- marketing_content: marketing_content,
110
- contact_email: contact_email,
111
- hide_softcover_footer:
112
- hide_softcover_footer,
113
- authors: authors,
114
- ga_account: ga_account
99
+ params = {
100
+ id: id,
101
+ files: files,
102
+ title: title,
103
+ slug: slug,
104
+ subtitle: subtitle,
105
+ description: description,
106
+ chapters: chapter_attributes,
107
+ prices: prices,
108
+ faq: faq,
109
+ testimonials: testimonials,
110
+ marketing_content: marketing_content,
111
+ contact_email: contact_email,
112
+ hide_softcover_footer: hide_softcover_footer,
113
+ authors: authors,
114
+ ga_account: ga_account,
115
+ remove_unused_media_bundles: options[:remove_unused_media_bundles]
116
+ }
117
+
118
+ res = @client.create_or_update_book params
115
119
 
116
120
  if res['errors']
117
121
  @errors = res['errors']
@@ -180,14 +184,14 @@ class Softcover::Book
180
184
  # => get checksums for all included files
181
185
  # => send each to /media API endpoint and then upload
182
186
 
183
- def process_media
187
+ def process_media(options={})
184
188
  Dir["media/*"].each do |media_dir|
185
189
  next unless File.directory?(media_dir) && !(media_dir =~ /^\./)
186
- process_media_directory media_dir
190
+ process_media_directory media_dir, options
187
191
  end
188
192
  end
189
193
 
190
- def process_media_directory(dir)
194
+ def process_media_directory(dir, options={})
191
195
  return false if @processed_media.include?(dir)
192
196
 
193
197
  puts "Processing #{dir} directory..."
@@ -196,7 +200,7 @@ class Softcover::Book
196
200
  file.ready?
197
201
  end
198
202
 
199
- upload_media! dir, files_to_upload
203
+ upload_media! dir, files_to_upload, options
200
204
 
201
205
  @processed_media.push dir
202
206
  end
@@ -207,13 +211,13 @@ class Softcover::Book
207
211
  end.compact
208
212
  end
209
213
 
210
- def upload_media!(path, files)
214
+ def upload_media!(path, files, options={})
211
215
  return if files.empty?
212
216
 
213
217
  manifest_path = File.join(path, "manifest.yml")
214
218
  manifest = File.exists?(manifest_path) ? File.read(manifest_path) : nil
215
219
 
216
- res = @client.get_media_upload_params path, files, manifest
220
+ res = @client.get_media_upload_params path, files, manifest, options
217
221
 
218
222
  if res['upload_params']
219
223
  media_uploader = Softcover::Uploader.new res
data/lib/softcover/cli.rb CHANGED
@@ -137,6 +137,8 @@ module Softcover
137
137
  desc: "Quiet output", type: :boolean
138
138
  method_option :silent, aliases: '-s',
139
139
  desc: "Silent output", type: :boolean
140
+ method_option :remove_unused_media_bundles, aliases: '-r',
141
+ desc: "Remove unused media bundles", type: :boolean
140
142
  def publish
141
143
  require 'softcover/commands/publisher'
142
144
 
@@ -151,6 +153,8 @@ module Softcover
151
153
  desc: "Run as daemon", type: :boolean
152
154
  method_option :watch, aliases: '-w', type: :boolean,
153
155
  force: false, desc: "Watch a directory to auto upload."
156
+ method_option :remove_unused_media_files, aliases: '-r',
157
+ desc: "Remove unused media files", type: :boolean
154
158
 
155
159
  # TODO: make screencasts dir .book configurable
156
160
  define_method "publish:media" do |dir=
@@ -66,11 +66,12 @@ module Softcover
66
66
  end
67
67
 
68
68
  # ============ Media ===========
69
- def get_media_upload_params(path, files, manifest=nil)
69
+ def get_media_upload_params(path, files, manifest=nil, options={})
70
70
  JSON post path_for(:books, book.id, :media),
71
71
  path: path,
72
72
  files: files,
73
- manifest: manifest
73
+ manifest: manifest,
74
+ remove_unused_media_files: options[:remove_unused_media_files]
74
75
  # TODO: handle errors
75
76
  end
76
77
 
@@ -7,7 +7,7 @@ module Softcover::Commands::Publisher
7
7
  def publish!(options={})
8
8
  return false unless current_book
9
9
 
10
- if current_book.create_or_update
10
+ if current_book.create_or_update(options)
11
11
  require 'ruby-progressbar'
12
12
  require 'curb'
13
13
  unless options[:quiet] || options[:silent]
@@ -47,18 +47,18 @@ module Softcover::Commands::Publisher
47
47
 
48
48
  if options[:daemon]
49
49
  pid = fork do
50
- run_publish_media
50
+ run_publish_media(options)
51
51
  end
52
52
 
53
53
  puts "Daemonized, pid: #{pid}"
54
54
  else
55
- run_publish_media
55
+ run_publish_media(options)
56
56
  end
57
57
 
58
58
  current_book
59
59
  end
60
60
 
61
- def run_publish_media
61
+ def run_publish_media(options={})
62
62
  if @watch
63
63
  puts "Watching..."
64
64
 
@@ -69,7 +69,7 @@ module Softcover::Commands::Publisher
69
69
 
70
70
  begin
71
71
  loop do
72
- process_media
72
+ process_media(options)
73
73
  sleep 1
74
74
  end
75
75
  rescue Interrupt
@@ -77,13 +77,13 @@ module Softcover::Commands::Publisher
77
77
  exit_with_message
78
78
  end
79
79
  else
80
- process_media
80
+ process_media(options)
81
81
  exit_with_message
82
82
  end
83
83
  end
84
84
 
85
- def process_media
86
- current_book.process_media
85
+ def process_media(options={})
86
+ current_book.process_media(options)
87
87
  end
88
88
 
89
89
  def exit_with_message
@@ -1,3 +1,3 @@
1
1
  module Softcover
2
- VERSION = "1.0.beta1"
2
+ VERSION = "1.0.beta2"
3
3
  end
data/softcover.gemspec CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |gem|
18
18
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
19
  gem.require_paths = ["lib"]
20
20
 
21
- gem.add_dependency 'polytexnic', '~> 1.0.beta1'
21
+ gem.add_dependency 'polytexnic', '~> 1.0.beta2'
22
22
  gem.add_dependency 'msgpack', '~> 0.4.2'
23
23
  gem.add_dependency 'nokogiri', '~> 1.6.0'
24
24
  gem.add_dependency 'thor', '~> 0.18.1'
@@ -5,6 +5,8 @@ describe Softcover::Commands::Publisher do
5
5
  before(:all) { generate_book }
6
6
  after(:all) { remove_book }
7
7
 
8
+ let(:publish_options) { { remove_unused_media_bundles: true } }
9
+
8
10
  describe "#publish" do
9
11
  context "publishing from non book directory" do
10
12
  before do
@@ -24,7 +26,7 @@ describe Softcover::Commands::Publisher do
24
26
  end
25
27
 
26
28
  it "publishes" do
27
- expect(subject.publish!).to be_true
29
+ expect(subject.publish!(publish_options)).to be_true
28
30
  end
29
31
  end
30
32
  end
@@ -45,7 +47,7 @@ describe Softcover::Commands::Publisher do
45
47
  chdir_to_book
46
48
  stub_create_book book
47
49
  stub_media_upload book
48
- subject.publish!
50
+ subject.publish! publish_options
49
51
  stub_destroy_book book
50
52
  end
51
53
 
@@ -64,7 +66,7 @@ describe Softcover::Commands::Publisher do
64
66
  chdir_to_book
65
67
  stub_create_book book
66
68
  stub_media_upload book
67
- subject.publish!
69
+ subject.publish!(publish_options)
68
70
  Softcover::BookConfig['id'] = 0
69
71
  stub_destroy_book_not_found book
70
72
  end
@@ -79,7 +81,7 @@ describe Softcover::Commands::Publisher do
79
81
  chdir_to_book
80
82
  stub_create_book book
81
83
  stub_media_upload book
82
- subject.publish!
84
+ subject.publish! publish_options
83
85
  Dir.chdir(File.dirname(__FILE__))
84
86
  end
85
87
 
@@ -67,7 +67,8 @@ module WebmockHelpers
67
67
  contact_email: book.contact_email,
68
68
  hide_softcover_footer: book.hide_custom_domain_footer,
69
69
  authors: book.authors,
70
- ga_account: book.ga_account
70
+ ga_account: book.ga_account,
71
+ remove_unused_media_bundles: true
71
72
  }.to_json,
72
73
  :headers => headers).
73
74
  to_return(:status => 200, :body => return_body, :headers => {})
@@ -122,7 +123,7 @@ module WebmockHelpers
122
123
  to_return(:status => 200, :body => "", :headers => {})
123
124
  end
124
125
 
125
- def stub_media_upload(book, dir='ebooks')
126
+ def stub_media_upload(book, dir='ebooks', options={})
126
127
  stub_s3_post
127
128
  stub_create_book(book)
128
129
 
@@ -132,7 +133,10 @@ module WebmockHelpers
132
133
  with(:body => {
133
134
  path: dir,
134
135
  files: files,
135
- manifest: nil}.to_json,
136
+ manifest: nil,
137
+ remove_unused_media_files:
138
+ options[:remove_unused_media_files]
139
+ }.to_json,
136
140
  :headers => headers).
137
141
  to_return(:status => 200, :body => {
138
142
  upload_params: files.map { |file|
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: softcover
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.beta1
4
+ version: 1.0.beta2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Hartl
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-06-23 00:00:00.000000000 Z
12
+ date: 2014-07-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: polytexnic
@@ -17,14 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - ~>
19
19
  - !ruby/object:Gem::Version
20
- version: 1.0.beta1
20
+ version: 1.0.beta2
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - ~>
26
26
  - !ruby/object:Gem::Version
27
- version: 1.0.beta1
27
+ version: 1.0.beta2
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: msgpack
30
30
  requirement: !ruby/object:Gem::Requirement