softcover 1.0.beta16 → 1.0.beta17

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: b8137c81992908717396867abb601cd2848c9b51
4
- data.tar.gz: 9eab005f7c11be7b6891e6155a184297ac68298c
3
+ metadata.gz: a010fdc3be4c539bbd087a1ed42186c73fb387b3
4
+ data.tar.gz: 2b556afbc60c97517329cdf3b393bdcd2bf5b8d2
5
5
  SHA512:
6
- metadata.gz: 887cd0da96df9dd87cd932fef09a4c2531bf2b6388fe1962269cefbb1e0026065807b20d6524e88d8ac504b62f2a3cf58a979836f32ea96fea958d830964ffba
7
- data.tar.gz: eda12cf4e9470df7ec1d42a1cd03c4794d47019066636f3e8954423bc4a6c5642fd78c1b43c07d427c6a9a7242fd98e9a8f45da85cd33b664875039ecaaeb90d
6
+ metadata.gz: 92958158366fb7334c6539127201e8f44b1afcf53577bf2c454caca838db1b7475a6a138771cc68296624b89d8d45174b37bb637b180fc49dd8016a2cf133099
7
+ data.tar.gz: dc274c4143c6843b52bdf4b1fc8acf733c5a72e99e912246314ace871ffd19c10a119deff2e1295413d59ae108a497d28d1f5ed3e04ab5271e76272404363e01
@@ -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
@@ -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
@@ -17,3 +17,5 @@
17
17
  % Include a command for the sake of the test suite.
18
18
  \newcommand{\softcover}{\texttt{softcover}}
19
19
 
20
+ % Include custom math example.
21
+ \newcommand{\unitvec}[1]{\ensuremath{\hat #1}}
@@ -1,3 +1,3 @@
1
1
  module Softcover
2
- VERSION = "1.0.beta16"
2
+ VERSION = "1.0.beta17"
3
3
  end
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
- # 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
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"
@@ -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.beta16
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.4.4
1074
+ rubygems_version: 2.2.2
1075
1075
  signing_key:
1076
1076
  specification_version: 4
1077
1077
  summary: A typesetting system for technical authors