paru 0.0.0

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.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/lib/paru.rb +1 -0
  3. data/lib/paru/pandoc.rb +111 -0
  4. metadata +45 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 46b8a00a662f9d90033d4f482e6b0110ba673a4e
4
+ data.tar.gz: 41321af06e4c06189acff7370192011046c25737
5
+ SHA512:
6
+ metadata.gz: 67154b11cf42a5ee23aae9ef99babdf9f66751eadaea20d7b72840151e11b88d85ed166899037acadeef155f5fceb50f4c2814a63de13081be0004f8a1ebd694
7
+ data.tar.gz: 2fdc46457d196cf98e60146f3a365f10b09b24b653fa7e3ed1656afc7ec80e5ea8f9735e03c4f7118343b68079cedd49326d4e43accd97d3098f8fb7bc2211f7
@@ -0,0 +1 @@
1
+ require 'paru/pandoc'
@@ -0,0 +1,111 @@
1
+ module Paru
2
+
3
+ require 'yaml'
4
+
5
+ # Pandoc is a wrapper around the pandoc system. See
6
+ # <http://pandoc.org/README.html> for details about pandoc. This file is
7
+ # basically a straightforward translation from command line program to ruby
8
+ # class
9
+
10
+ class Pandoc
11
+
12
+ def initialize &block
13
+ @options = {}
14
+ configure(&block) if block_given?
15
+ end
16
+
17
+ def configure &block
18
+ instance_eval(&block)
19
+ self
20
+ end
21
+
22
+ # Converts input string to output string using the pandoc invocation
23
+ # configures in this Pandoc instance.
24
+ def convert input
25
+ output = ''
26
+ IO.popen(to_command, 'r+') do |p|
27
+ p << input
28
+ p.close_write
29
+ output << p.read
30
+ end
31
+ output
32
+ end
33
+ alias << convert
34
+
35
+ def to_command option_sep = " \\\n\t"
36
+ "pandoc\t#{to_option_string option_sep}"
37
+ end
38
+
39
+ def to_option_string option_sep
40
+ options_arr = []
41
+ @options.each do |option, value|
42
+ option_string = "--#{option.to_s.gsub '_', '-'}"
43
+
44
+ case value
45
+ when TrueClass then
46
+ # Flags don't have a value, only its name
47
+ # For example: --standalone
48
+ options_arr.push "#{option_string}"
49
+ when FalseClass then
50
+ # Skip this option; consider a flag with value false as unset
51
+ when Array then
52
+ # This option can occur multiple times: list each with its value.
53
+ # For example: --css=main.css --css=print.css
54
+ options_arr.push value.map {|val| "#{option_string}=#{val.to_s}"}.join(option_sep)
55
+ else
56
+ # All options that aren't flags and can occur only once have the
57
+ # same pattern: --option=value
58
+ options_arr.push "#{option_string}=#{value.to_s}"
59
+ end
60
+ end
61
+ options_arr.join(option_sep)
62
+ end
63
+
64
+ # Pandoc has a number of command line options. Most are simple options,
65
+ # like flags, that can be set only once. Other options can occur more than
66
+ # once, such as the css option: to add more than one css file to a
67
+ # generated standalone html file, use the css options once for each
68
+ # stylesheet to include. Other options do have the pattern key[:value],
69
+ # which can also occur multiple times, such as metadata.
70
+ #
71
+ # All options are specified in a pandoc_options.yaml. If it is an option
72
+ # that can occur only once, the value of the option in that yaml file is
73
+ # its default value. If the option can occur multiple times, its value is
74
+ # an array with one value, the default value.
75
+ #
76
+ # For each of these options a method is defined as follows:
77
+ OPTIONS = YAML.load_file File.join(__dir__, 'pandoc_options.yaml')
78
+
79
+ OPTIONS.keys.each do |option|
80
+ if OPTIONS[option].is_a? Array then
81
+
82
+ # option can be set multiple times, for example adding multiple css
83
+ # files
84
+
85
+ default = OPTIONS[option][0]
86
+
87
+ define_method(option) do |value = default|
88
+ if @options[option] then
89
+ @options[option].push value
90
+ else
91
+ @options[option] = [value]
92
+ end
93
+ self
94
+ end
95
+
96
+ else
97
+
98
+ # option can be set only once, for example a flag or a template
99
+
100
+ default = OPTIONS[option]
101
+ define_method(option) do |value = default|
102
+ @options[option] = value
103
+ self
104
+ end
105
+
106
+ end
107
+ end
108
+
109
+ end
110
+
111
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: paru
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Huub de Beer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-04 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Use Pandoc (http://www.pandoc.org) with ruby
14
+ email: Huub@heerdebeer.org
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/paru.rb
20
+ - lib/paru/pandoc.rb
21
+ homepage: http://rubygems.org/gems/paru
22
+ licenses:
23
+ - GPL3
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 2.2.2
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: Paru is a ruby wrapper around pandoc
45
+ test_files: []