softcover 1.0.beta16 → 1.0.beta17
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.
- checksums.yaml +4 -4
- data/lib/softcover/book.rb +6 -1
- data/lib/softcover/mathjax.rb +6 -7
- data/lib/softcover/template/latex_styles/custom.sty +2 -0
- data/lib/softcover/version.rb +1 -1
- data/spec/book_spec.rb +11 -0
- data/spec/commands/publisher_spec.rb +140 -140
- data/spec/mathjax_spec.rb +4 -4
- data/spec/webmock_helpers.rb +2 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a010fdc3be4c539bbd087a1ed42186c73fb387b3
|
4
|
+
data.tar.gz: 2b556afbc60c97517329cdf3b393bdcd2bf5b8d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 92958158366fb7334c6539127201e8f44b1afcf53577bf2c454caca838db1b7475a6a138771cc68296624b89d8d45174b37bb637b180fc49dd8016a2cf133099
|
7
|
+
data.tar.gz: dc274c4143c6843b52bdf4b1fc8acf733c5a72e99e912246314ace871ffd19c10a119deff2e1295413d59ae108a497d28d1f5ed3e04ab5271e76272404363e01
|
data/lib/softcover/book.rb
CHANGED
@@ -115,7 +115,8 @@ class Softcover::Book
|
|
115
115
|
authors: authors,
|
116
116
|
ga_account: ga_account,
|
117
117
|
repo_url: repo_url,
|
118
|
-
remove_unused_media_bundles: options[:remove_unused_media_bundles]
|
118
|
+
remove_unused_media_bundles: options[:remove_unused_media_bundles],
|
119
|
+
custom_math: custom_math
|
119
120
|
}
|
120
121
|
|
121
122
|
res = @client.create_or_update_book params
|
@@ -236,6 +237,10 @@ class Softcover::Book
|
|
236
237
|
end
|
237
238
|
end
|
238
239
|
|
240
|
+
def custom_math
|
241
|
+
Softcover::Mathjax.custom_macros
|
242
|
+
end
|
243
|
+
|
239
244
|
private
|
240
245
|
def method_missing(name, *args, &block)
|
241
246
|
@manifest.send(name) || @marketing.send(name) || nil
|
data/lib/softcover/mathjax.rb
CHANGED
@@ -53,14 +53,13 @@ module Softcover
|
|
53
53
|
AMS_HTML = '/' + MATHJAX + 'TeX-AMS_HTML'
|
54
54
|
AMS_SVG = MATHJAX + 'TeX-AMS-MML_SVG'
|
55
55
|
|
56
|
+
# Returns the custom macros as defined in the custom style file.
|
57
|
+
def self.custom_macros
|
58
|
+
extract_macros(Softcover.custom_styles)
|
59
|
+
end
|
56
60
|
|
57
61
|
private
|
58
62
|
|
59
|
-
# Returns the custom macros as defined in the custom style file.
|
60
|
-
def self.custom_macros
|
61
|
-
extract_macros(Softcover.custom_styles)
|
62
|
-
end
|
63
|
-
|
64
63
|
# Extracts and formats the macros from the given string of style commands.
|
65
64
|
# The output format is compatible with the macro configuration described
|
66
65
|
# at http://docs.mathjax.org/en/latest/tex.html.
|
@@ -71,13 +70,13 @@ module Softcover
|
|
71
70
|
cmd_no_args = /^\s*\\newcommand\{\\(.*?)\}\{(.*)\}/
|
72
71
|
cna = styles.scan(cmd_no_args).map do |name, definition|
|
73
72
|
escaped_definition = definition.gsub('\\', '\\\\\\\\')
|
74
|
-
%(#{name}: "#{escaped_definition}")
|
73
|
+
%("#{name}": "#{escaped_definition}")
|
75
74
|
end
|
76
75
|
# Then grab the commands with arguments.
|
77
76
|
cmd_with_args = /^\s*\\newcommand\{\\(.*?)\}\[(\d+)\]\{(.*)\}/
|
78
77
|
cwa = styles.scan(cmd_with_args).map do |name, number, definition|
|
79
78
|
escaped_definition = definition.gsub('\\', '\\\\\\\\')
|
80
|
-
%(#{name}: ["#{escaped_definition}", #{number}])
|
79
|
+
%("#{name}": ["#{escaped_definition}", #{number}])
|
81
80
|
end
|
82
81
|
(cna + cwa).join(",\n")
|
83
82
|
end
|
data/lib/softcover/version.rb
CHANGED
data/spec/book_spec.rb
CHANGED
@@ -36,6 +36,17 @@ describe Softcover::Book do
|
|
36
36
|
its(:testimonials) { should_not be_empty }
|
37
37
|
its(:marketing_content) { should be_empty }
|
38
38
|
end
|
39
|
+
|
40
|
+
describe "custom math" do
|
41
|
+
let(:math) do
|
42
|
+
"\"softcover\": \"\\\\texttt{softcover}\"" +
|
43
|
+
",\n\"unitvec\": [\"{\\\\hat #1}\", 1]"
|
44
|
+
end
|
45
|
+
|
46
|
+
its(:custom_math) do
|
47
|
+
should eq math
|
48
|
+
end
|
49
|
+
end
|
39
50
|
end
|
40
51
|
end
|
41
52
|
end
|
@@ -1,140 +1,140 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
#
|
115
|
-
#
|
116
|
-
#
|
117
|
-
|
118
|
-
#
|
119
|
-
#
|
120
|
-
#
|
121
|
-
#
|
122
|
-
|
123
|
-
#
|
124
|
-
#
|
125
|
-
#
|
126
|
-
#
|
127
|
-
#
|
128
|
-
#
|
129
|
-
#
|
130
|
-
|
131
|
-
#
|
132
|
-
#
|
133
|
-
#
|
134
|
-
#
|
135
|
-
#
|
136
|
-
#
|
137
|
-
#
|
138
|
-
|
139
|
-
|
140
|
-
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Softcover::Commands::Publisher do
|
4
|
+
let(:book) { Softcover::Utils.current_book }
|
5
|
+
before(:all) { generate_book }
|
6
|
+
after(:all) { remove_book }
|
7
|
+
|
8
|
+
let(:publish_options) { { remove_unused_media_bundles: true } }
|
9
|
+
|
10
|
+
describe "#publish" do
|
11
|
+
context "publishing from non book directory" do
|
12
|
+
before do
|
13
|
+
chdir_to_non_book
|
14
|
+
end
|
15
|
+
|
16
|
+
it "rejects the publish" do
|
17
|
+
expect(subject.publish!).to be_false
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context "publishing from book directory" do
|
22
|
+
before do
|
23
|
+
chdir_to_book
|
24
|
+
stub_create_book book
|
25
|
+
stub_media_upload book
|
26
|
+
end
|
27
|
+
|
28
|
+
it "publishes" do
|
29
|
+
expect(subject.publish!(publish_options)).to be_true
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "#unpublish" do
|
35
|
+
context "unpublishing from non book directory" do
|
36
|
+
before do
|
37
|
+
chdir_to_non_book
|
38
|
+
end
|
39
|
+
|
40
|
+
it "rejects the unpublish" do
|
41
|
+
expect(subject.unpublish!).to be_false
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context "unpublishing from book directory" do
|
46
|
+
before do
|
47
|
+
chdir_to_book
|
48
|
+
stub_create_book book
|
49
|
+
stub_media_upload book
|
50
|
+
subject.publish! publish_options
|
51
|
+
stub_destroy_book book
|
52
|
+
end
|
53
|
+
|
54
|
+
it "unpublishes" do
|
55
|
+
expect(subject.unpublish!).to be_true
|
56
|
+
end
|
57
|
+
|
58
|
+
it "removes book config" do
|
59
|
+
subject.unpublish!
|
60
|
+
expect(Softcover::BookConfig.exists?).to be_false
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context "unpublishing from book directory with invalid ID" do
|
65
|
+
before do
|
66
|
+
chdir_to_book
|
67
|
+
stub_create_book book
|
68
|
+
stub_media_upload book
|
69
|
+
subject.publish!(publish_options)
|
70
|
+
Softcover::BookConfig['id'] = 0
|
71
|
+
stub_destroy_book_not_found book
|
72
|
+
end
|
73
|
+
|
74
|
+
it "does not unpublish" do
|
75
|
+
expect(subject.unpublish!).to be_false
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context "unpublishing outside book directory" do
|
80
|
+
before do
|
81
|
+
chdir_to_book
|
82
|
+
stub_create_book book
|
83
|
+
stub_media_upload book
|
84
|
+
subject.publish! publish_options
|
85
|
+
Dir.chdir(File.dirname(__FILE__))
|
86
|
+
end
|
87
|
+
|
88
|
+
context "with valid slug option" do
|
89
|
+
before { stub_destroy_book_by_slug book }
|
90
|
+
|
91
|
+
it "unpublishes" do
|
92
|
+
expect(subject.unpublish!(book.slug)).to be_true
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context "with invalid slug option" do
|
97
|
+
let(:slug) { "error" }
|
98
|
+
before { stub_destroy_book_by_invalid_slug slug }
|
99
|
+
|
100
|
+
it "does not unpublish" do
|
101
|
+
expect(subject.unpublish!(slug)).to be_false
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
describe "#publish_media" do
|
108
|
+
before do
|
109
|
+
chdir_to_book
|
110
|
+
book.id = 1
|
111
|
+
stub_media_upload book
|
112
|
+
end
|
113
|
+
|
114
|
+
# it "should start with 0 processed_media" do
|
115
|
+
# expect(book.processed_media.length).to eq 0
|
116
|
+
# end
|
117
|
+
|
118
|
+
# it "processes media" do
|
119
|
+
# subject.publish_media!
|
120
|
+
# expect(book.processed_media.length).to be > 0
|
121
|
+
# end
|
122
|
+
|
123
|
+
# it "daemonizes" do
|
124
|
+
# subject.should_receive(:fork) do |&blk|
|
125
|
+
# blk.call
|
126
|
+
# end
|
127
|
+
# subject.publish_media! daemon: true
|
128
|
+
# expect(book.processed_media.length).to be > 0
|
129
|
+
# end
|
130
|
+
|
131
|
+
# it "watches" do
|
132
|
+
# subject.should_receive(:loop) do |&blk|
|
133
|
+
# blk.call
|
134
|
+
# end
|
135
|
+
# subject.publish_media! watch: true
|
136
|
+
# expect(book.processed_media.length).to be > 0
|
137
|
+
# end
|
138
|
+
|
139
|
+
end
|
140
|
+
end
|
data/spec/mathjax_spec.rb
CHANGED
@@ -38,8 +38,8 @@ describe Softcover::Mathjax do
|
|
38
38
|
|
39
39
|
let(:polytex) { 'PolyTeX: "Poly{\\\\TeX}"' }
|
40
40
|
let(:polytexnic) { 'PolyTeXnic: "Poly{\\\\TeX}nic"' }
|
41
|
-
let(:foo) { 'foo: "{x}"' }
|
42
|
-
let(:bar) { 'bar: ["\\\\textbf{#1}", 1]' }
|
41
|
+
let(:foo) { '"foo": "{x}"' }
|
42
|
+
let(:bar) { '"bar": ["\\\\textbf{#1}", 1]' }
|
43
43
|
let(:config) { mathjax.config }
|
44
44
|
|
45
45
|
it "should not raise an error" do
|
@@ -52,8 +52,8 @@ describe Softcover::Mathjax do
|
|
52
52
|
context '#escaped_config' do
|
53
53
|
let(:polytex) { 'PolyTeX: "Poly{\\\\\\\\TeX}"' }
|
54
54
|
let(:polytexnic) { 'PolyTeXnic: "Poly{\\\\\\\\TeX}nic"' }
|
55
|
-
let(:foo) { 'foo: "{x}"' }
|
56
|
-
let(:bar) { 'bar: ["\\\\\\\\textbf{#1}", 1]' }
|
55
|
+
let(:foo) { '"foo": "{x}"' }
|
56
|
+
let(:bar) { '"bar": ["\\\\\\\\textbf{#1}", 1]' }
|
57
57
|
let(:config) { mathjax.escaped_config }
|
58
58
|
|
59
59
|
it_should_behave_like "config"
|
data/spec/webmock_helpers.rb
CHANGED
@@ -70,7 +70,8 @@ module WebmockHelpers
|
|
70
70
|
authors: book.authors,
|
71
71
|
ga_account: book.ga_account,
|
72
72
|
repo_url: book.repo_url,
|
73
|
-
remove_unused_media_bundles: true
|
73
|
+
remove_unused_media_bundles: true,
|
74
|
+
custom_math: book.custom_math
|
74
75
|
}.to_json,
|
75
76
|
:headers => headers).
|
76
77
|
to_return(:status => 200, :body => return_body, :headers => {})
|
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.
|
4
|
+
version: 1.0.beta17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Hartl
|
@@ -1071,7 +1071,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
1071
1071
|
version: 1.3.1
|
1072
1072
|
requirements: []
|
1073
1073
|
rubyforge_project:
|
1074
|
-
rubygems_version: 2.
|
1074
|
+
rubygems_version: 2.2.2
|
1075
1075
|
signing_key:
|
1076
1076
|
specification_version: 4
|
1077
1077
|
summary: A typesetting system for technical authors
|