polytexnic 1.0.beta1 → 1.0.beta2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 751a1b5ecbbcd95df78fdc4651d8ec270990abbb
4
- data.tar.gz: b57645b0af7b1d4c1a3067f0a2d8d954937348fc
3
+ metadata.gz: 313a786bc9e773eff07b9930cf84c7afa76bd4dc
4
+ data.tar.gz: 0544d7a35b333d101098aa1dce3e9fed8e164d2f
5
5
  SHA512:
6
- metadata.gz: 44ca3dac0ba83a5089e4066f82ec3330010c3e4020bfee990225282530d52c72cc972842ea63386fd2419b9025579014b2545bc2c1b262809c18c43de449a78f
7
- data.tar.gz: 053ea3fcf06caac0461614417ca3b856fea2632dcf28491608dfe01445a745cf45e011a2488caeed12ddd38c42ea2a77449aeabbabf9cd4e68790560e5c11d44
6
+ metadata.gz: 62213c15e21b7058a80b825fe4c52e11dd0b367ee3bbf325621e50f5ed02715027882c1ab6723af1f63dff15394dbaa242de889cf0ee1dd5685035c70d54f090
7
+ data.tar.gz: 6bc8b4967092469ec5dd83799001db23afe8b70fa03d2e676e89a618ff386c40103d2c2693c732f70f5fb00b66e25f836704b921640d5910b866ebf3f46509aa
@@ -48,6 +48,7 @@ module Polytexnic
48
48
  doc = cache_literal(add_commands(polytex))
49
49
  inline_verbatim(doc)
50
50
  cache_hrefs(doc)
51
+ expand_input!(doc, Proc.new { |source| cache_literal(source) }, 'tex')
51
52
  remove_comments(doc)
52
53
  double_backslashes(cache_display_inline_math(doc))
53
54
  end
@@ -12,7 +12,11 @@ module Polytexnic
12
12
  # Literal environments are hashed and passed through the pipeline
13
13
  # so that we can process things like refs and hyperrefs using gsubs.
14
14
  def clean_latex_document
15
- cache_literal(@polytex, :latex)
15
+ cache_literal(@polytex, :latex).tap do |doc|
16
+ expand_input!(doc,
17
+ Proc.new { |source| cache_literal(source, :latex) },
18
+ 'tex')
19
+ end
16
20
  end
17
21
 
18
22
  # Convert GIFs to PNGs.
@@ -86,10 +86,12 @@ module Polytexnic
86
86
  def to_polytex
87
87
  math_cache = {}
88
88
  cleaned_markdown = cache_code_environments(@source)
89
+ expand_input!(cleaned_markdown,
90
+ Proc.new { |source| cache_code_environments(source) })
91
+
89
92
  puts cleaned_markdown if debug?
90
93
  cleaned_markdown.tap do |markdown|
91
94
  convert_code_inclusion(markdown)
92
- expand_input(markdown)
93
95
  cache_latex_literal(markdown)
94
96
  cache_raw_latex(markdown)
95
97
  cache_image_locations(markdown)
@@ -188,14 +190,6 @@ module Polytexnic
188
190
  end
189
191
  end
190
192
 
191
- # Expands '\input' command by processing & inserting the target source.
192
- def expand_input(text)
193
- text.gsub!(/^[ \t]*\\input\{(.*?)\}[ \t]*$/) do
194
- source = File.read("#{$1}.md")
195
- Polytexnic::Pipeline.new(source, source: :markdown).polytex
196
- end
197
- end
198
-
199
193
  # Restores raw code from the cache.
200
194
  def restore_hashed_content(text)
201
195
  $cache.each do |key, value|
@@ -31,6 +31,18 @@ module Polytexnic
31
31
  @tralics ||= executable
32
32
  end
33
33
 
34
+
35
+ # Expands '\input' command by processing & inserting the target source.
36
+ def expand_input!(text, code_function, ext = 'md')
37
+ text.gsub!(/^[ \t]*\\input\{(.*?)\}[ \t]*$/) do
38
+ included_text = File.read("#{$1}.#{ext}")
39
+ code_function.call(included_text).tap do |clean_text|
40
+ # Recursively substitute '\input' in included text.
41
+ expand_input!(clean_text, code_function, ext)
42
+ end
43
+ end
44
+ end
45
+
34
46
  # Returns true for OS X Mountain Lion (10.8) and later.
35
47
  def os_x_newer?
36
48
  os_x? && !os_x_older?
@@ -1,3 +1,3 @@
1
1
  module Polytexnic
2
- VERSION = "1.0.beta1"
2
+ VERSION = "1.0.beta2"
3
3
  end
@@ -531,10 +531,33 @@ def hello; puts 'hello'; end
531
531
 
532
532
  describe '\input command' do
533
533
  let(:external_file) { 'foo.md' }
534
- before { File.write(external_file, input) }
535
- after { File.unlink(external_file) }
534
+ let(:nested_external_file) { 'bar.md' }
535
+ let(:input) do <<-'EOS'
536
+ Lorem ipsum
537
+ ```ruby
538
+ def foo; 'foo'; end
539
+ ```
540
+ Lorem *ipsum* dolor sit amet
541
+
542
+ \input{bar}
543
+ EOS
544
+ end
545
+ let(:nested_input) do <<-'EOS'
546
+ Lorem ipsum
547
+ ```python
548
+ def bar(): return "bar"
549
+ ```
550
+ EOS
551
+ end
552
+ before do
553
+ File.write(external_file, input)
554
+ File.write(nested_external_file, nested_input)
555
+ end
556
+ after do
557
+ File.unlink(external_file)
558
+ File.unlink(nested_external_file)
559
+ end
536
560
 
537
- let(:input) { 'lorem *ipsum* dolor sit amet' }
538
561
  let(:output) do
539
562
  Polytexnic::Pipeline.new(input, source: :markdown).polytex
540
563
  end
@@ -0,0 +1,51 @@
1
+ # encoding=utf-8
2
+ require 'spec_helper'
3
+
4
+ describe 'Polytexnic::Pipeline#to_html' do
5
+
6
+ let(:pipeline) { Polytexnic::Pipeline.new(polytex) }
7
+ subject(:processed_text) { pipeline.to_html }
8
+
9
+ describe '\input command' do
10
+ let(:external_file) { 'foo.tex' }
11
+ let(:nested_external_file) { 'bar.tex' }
12
+ let(:input) do <<-'EOS'
13
+ Lorem ipsum
14
+ %= lang:ruby
15
+ \begin{code}
16
+ def foo; 'foo'; end
17
+ \end{code}
18
+ Lorem \emph{ipsum} dolor sit amet
19
+
20
+ \input{bar}
21
+ EOS
22
+ end
23
+ let(:nested_input) do <<-'EOS'
24
+ Lorem ipsum
25
+ %= lang:python
26
+ \begin{code}
27
+ def bar(): return "bar"
28
+ \end{code}
29
+ EOS
30
+ end
31
+ before do
32
+ File.write(external_file, input)
33
+ File.write(nested_external_file, nested_input)
34
+ end
35
+ after do
36
+ File.unlink(external_file)
37
+ File.unlink(nested_external_file)
38
+ end
39
+
40
+ let(:polytex) { "\\chapter{Foo}\n\n \\input{foo} " }
41
+ let(:foo_html) do
42
+ '<div class="code"><div class="highlight"><pre><span class="k">def</span> <span class="nf">foo</span>'
43
+ end
44
+ let(:bar_html) do
45
+ '<div class="code"><div class="highlight"><pre><span class="k">def</span> <span class="nf">bar</span><span class="p">():'
46
+ end
47
+
48
+ it { should include foo_html }
49
+ it { should include bar_html }
50
+ end
51
+ end
@@ -217,5 +217,49 @@ end
217
217
  it { should include '\image{bar.png}' }
218
218
  it { should include '\imagebox{baz.png}' }
219
219
  end
220
+
221
+ describe '\input command' do
222
+ let(:external_file) { 'foo.tex' }
223
+ let(:nested_external_file) { 'bar.tex' }
224
+ let(:input) do <<-'EOS'
225
+ Lorem ipsum
226
+ %= lang:ruby
227
+ \begin{code}
228
+ def foo; 'foo'; end
229
+ \end{code}
230
+ Lorem \emph{ipsum} dolor sit amet
231
+
232
+ \input{bar}
233
+ EOS
234
+ end
235
+ let(:nested_input) do <<-'EOS'
236
+ Lorem ipsum
237
+ %= lang:python
238
+ \begin{code}
239
+ def bar(): return "bar"
240
+ \end{code}
241
+ EOS
242
+ end
243
+ before do
244
+ File.write(external_file, input)
245
+ File.write(nested_external_file, nested_input)
246
+ end
247
+ after do
248
+ File.unlink(external_file)
249
+ File.unlink(nested_external_file)
250
+ end
251
+
252
+ let(:polytex) { "\\chapter{Foo}\n\n \\input{foo} " }
253
+ let(:foo_latex) do
254
+ '\PY{k}{def} \PY{n+nf}{foo}\PY{p}{;}'
255
+ end
256
+ let(:bar_latex) do
257
+ '\PY{k}{def} \PY{n+nf}{bar}\PY{p}{(}\PY{p}{)}\PY{p}{:}'
258
+ end
259
+
260
+ it { should include foo_latex }
261
+ it { should include bar_latex }
262
+ it { should_not include 'xmlelement' }
263
+ end
220
264
  end
221
265
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: polytexnic
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: nokogiri
@@ -256,6 +256,7 @@ files:
256
256
  - spec/to_html/eqref_spec.rb
257
257
  - spec/to_html/footnote_spec.rb
258
258
  - spec/to_html/graphics_and_figures_spec.rb
259
+ - spec/to_html/input_spec.rb
259
260
  - spec/to_html/lists_spec.rb
260
261
  - spec/to_html/literal_environments/code_spec.rb
261
262
  - spec/to_html/literal_environments/math_spec.rb
@@ -318,6 +319,7 @@ test_files:
318
319
  - spec/to_html/eqref_spec.rb
319
320
  - spec/to_html/footnote_spec.rb
320
321
  - spec/to_html/graphics_and_figures_spec.rb
322
+ - spec/to_html/input_spec.rb
321
323
  - spec/to_html/lists_spec.rb
322
324
  - spec/to_html/literal_environments/code_spec.rb
323
325
  - spec/to_html/literal_environments/math_spec.rb