RbST 0.6.2 → 0.6.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +14 -5
  3. data/RbST.gemspec +2 -2
  4. data/lib/rbst.rb +11 -3
  5. data/test/test_rbst.rb +14 -6
  6. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1d8bf66c8e76283e29fb0deeb4c7d2529e262dd2ba8e261db0cf10cdd3151226
4
- data.tar.gz: 6d4064403ac311404db35f727cd4d9ed04a93e326b6b5a50939b73142328de20
3
+ metadata.gz: 3632d5d2bed30d24d169d60781845255f7c66cbe6826aed0906e738315ae8b9c
4
+ data.tar.gz: 0b3152c97445b15c1614a2778baa6482ad3420bd9de3d81c54179f69e5475e52
5
5
  SHA512:
6
- metadata.gz: 3d739b2d16a84876a78c564550c39257ccf482fa74f0e232d9b40b50b9f8d8721ef81b212c97315eedf424c05455defb84c1880796535adbabd3bd927acd94b8
7
- data.tar.gz: 4fcaf3f2d1f4ed32deda92bab7bbf23ea1a6c32ec6dbc16b066be5e3d55b0da011bd7715ced98054723de5fde12a38c2533d28c1bef52bdc74ae87b79a7908f6
6
+ metadata.gz: f4ea41b4caf0896e0c97df51d717a9206f34ac45d098567876ec7c382f11fe5a60a34906beca6442551dbd8bbbd00b1b43bb1aa7091afa81d8315c84636c624f
7
+ data.tar.gz: 9a8a99fdaa8478afd723c7d96cf8e878b685c123639c6dbf9aec183d771f2c141413ce0ef46935ce5e597ad22ccfd5f5fae0ed472fdc6c5fdc6ab048df0af83d
data/README.md CHANGED
@@ -26,18 +26,27 @@ Then run `bundle install`
26
26
 
27
27
  ```ruby
28
28
  require 'rbst'
29
- @html = RbST.new('/some/file.rst').to_html
30
- # or
31
29
  @latex = RbST.new('*hello*').to_latex
32
30
  ```
33
31
 
34
- This takes the reStructuredText formatted file and converts it to either HTML
35
- or LaTeX. The first argument can be either a file or a string.
32
+ This takes the reStructuredText formatted string and converts it to LaTeX.
33
+
34
+ The first argument can be either a string or an array of one or more file
35
+ paths. The files will be concatenated together with a blank line between
36
+ each and used as input.
37
+
38
+ ```ruby
39
+ # One file path as a single-element array.
40
+ RbST.new(['/path/to/file.rst']).to_html
41
+
42
+ # Multiple file paths as an array.
43
+ RbST.new(['/path/to/file1.rst', '/path/to/file2.rst']).to_html
44
+ ```
36
45
 
37
46
  You can also use the `convert` class method to output HTML:
38
47
 
39
48
  ```ruby
40
- puts RbST.convert('/some/file.rst')
49
+ puts RbST.convert('*hello*')
41
50
  ```
42
51
 
43
52
  Arguments can be passed to `#to_html`, `#to_latex`, `new` or `convert`,
@@ -2,13 +2,13 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'RbST'
5
- s.version = '0.6.2'
5
+ s.version = '0.6.3'
6
6
  s.licenses = ['MIT']
7
7
  s.summary = "A Ruby gem for processing reStructuredText via Python's Docutils."
8
8
  s.description = "A Ruby gem for processing reStructuredText via Python's Docutils."
9
9
  s.authors = ['William Melody']
10
10
  s.email = 'hi@williammelody.com'
11
- s.date = '2020-03-18'
11
+ s.date = '2020-03-24'
12
12
  s.extra_rdoc_files = [
13
13
  'LICENSE',
14
14
  'README.md'
@@ -54,11 +54,19 @@ class RbST
54
54
  @@python_path
55
55
  end
56
56
 
57
- # Takes a string or file path plus any additional options and creates a new
58
- # converter object.
57
+ # Takes a string or array of file paths plus any additional options and
58
+ # creates a new converter object.
59
59
  def initialize(*args)
60
60
  target = args.shift
61
- @target = File.exist?(target) ? File.read(target) : target rescue target
61
+ if target.is_a?(String)
62
+ @target = target
63
+ elsif target.is_a?(Array)
64
+ @target = ''
65
+ target.each_with_index do |path, i|
66
+ @target += "\n" if i.positive?
67
+ @target += File.exist?(path) ? File.read(path) : path rescue path
68
+ end
69
+ end
62
70
  @options = args
63
71
  end
64
72
 
@@ -16,7 +16,7 @@ describe RbST do
16
16
  end
17
17
 
18
18
  it 'should call bare rest2parts when passed no options' do
19
- converter = RbST.new(@rst_file)
19
+ converter = RbST.new([@rst_file])
20
20
  converter \
21
21
  .expects(:execute) \
22
22
  .with("python #{@rst2parts_path}/rst2html.py") \
@@ -28,7 +28,7 @@ describe RbST do
28
28
  executables = { html: '/some/path/2html.py' }
29
29
  default_executables = RbST.executables
30
30
  RbST.executables = executables
31
- converter = RbST.new(@rst_file)
31
+ converter = RbST.new([@rst_file])
32
32
  converter \
33
33
  .expects(:execute) \
34
34
  .with("python #{executables[:html]}") \
@@ -48,7 +48,7 @@ describe RbST do
48
48
  end
49
49
 
50
50
  it 'should convert ReST to html' do
51
- html = RbST.new(@rst_file).to_html
51
+ html = RbST.new([@rst_file]).to_html
52
52
  assert_equal(
53
53
  File.read(@html_file),
54
54
  html
@@ -56,7 +56,7 @@ describe RbST do
56
56
  end
57
57
 
58
58
  it 'should convert ReST to LaTeX' do
59
- latex = RbST.new(@rst_file).to_latex
59
+ latex = RbST.new([@rst_file]).to_latex
60
60
  assert_equal(
61
61
  File.read(@latex_file),
62
62
  latex
@@ -65,7 +65,7 @@ describe RbST do
65
65
 
66
66
  [:html, :latex].each do |f|
67
67
  it "should accept options on #to_#{f}" do
68
- converter = RbST.new(@rst_file)
68
+ converter = RbST.new([@rst_file])
69
69
  converter \
70
70
  .expects(:execute) \
71
71
  .with("python #{@rst2parts_path}/rst2#{f}.py --raw-enabled") \
@@ -140,9 +140,17 @@ describe RbST do
140
140
  )
141
141
  end
142
142
 
143
+ it 'should preserve file paths in strings without array' do
144
+ output = RbST.new(@rst_file).to_html(part: :fragment)
145
+ assert_equal(
146
+ %|<p>#{@rst_file}</p>\n|,
147
+ output
148
+ )
149
+ end
150
+
143
151
  it 'should execute with custom python path' do
144
152
  RbST.python_path = '/usr/bin/env python3'
145
- converter = RbST.new(@rst_file)
153
+ converter = RbST.new([@rst_file])
146
154
  converter \
147
155
  .expects(:execute) \
148
156
  .with("/usr/bin/env python3 #{@rst2parts_path}/rst2html.py") \
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: RbST
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Melody
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-18 00:00:00.000000000 Z
11
+ date: 2020-03-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest