heycarsten-bakery 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,2 @@
1
+ == 0.0.1 / 2008-12-06
2
+ * Created gem scaffold.
@@ -0,0 +1,12 @@
1
+ bakery.gemspec
2
+ History.txt
3
+ History.txt
4
+ lib/bakery.rb
5
+ lib/bakery/command.rb
6
+ lib/bakery/transformation.rb
7
+ Manifest.txt
8
+ Rakefile
9
+ README.txt
10
+ test/helper.rb
11
+ test/suite.rb
12
+ test/test_bakery.rb
@@ -0,0 +1,33 @@
1
+ bakery
2
+ by Carsten Nielsen
3
+ http://github.com/heycarsten/bakery
4
+
5
+ = Bakery
6
+
7
+ When you just want to render a fragment of LaTeX and move on with your life.
8
+
9
+
10
+ = LICENSE
11
+
12
+ MIT License
13
+
14
+ Copyright (C) 2008 Carsten Nielsen
15
+
16
+ Permission is hereby granted, free of charge, to any person obtaining
17
+ a copy of this software and associated documentation files (the
18
+ 'Software'), to deal in the Software without restriction, including
19
+ without limitation the rights to use, copy, modify, merge, publish,
20
+ distribute, sublicense, and/or sell copies of the Software, and to
21
+ permit persons to whom the Software is furnished to do so, subject to
22
+ the following conditions:
23
+
24
+ The above copyright notice and this permission notice shall be
25
+ included in all copies or substantial portions of the Software.
26
+
27
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
28
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
29
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
30
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
31
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
32
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
33
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,21 @@
1
+ require 'rubygems'
2
+ require 'hoe'
3
+ require './lib/bakery'
4
+
5
+ Hoe.new('bakery', Bakery::VERSION) do |p|
6
+ p.author = 'Carsten Nielsen'
7
+ p.email = 'heycarsten@gmail.com'
8
+ p.summary = 'A library for turning fragments of LaTeX into images'
9
+ p.url = 'http://github.com/heycarsten/bakery'
10
+ end
11
+
12
+ desc 'Open an irb session preloaded with this library'
13
+ task :console do
14
+ `irb -rubygems -r ./lib/bakery.rb`
15
+ end
16
+
17
+ task :coverage do
18
+ system 'rm -rf coverage'
19
+ system 'rcov test/test_*.rb'
20
+ system 'open coverage/index.html'
21
+ end
@@ -0,0 +1,24 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'bakery'
3
+ s.version = '0.0.1'
4
+ s.summary = 'A library for turning fragments of LaTeX into images'
5
+ s.email = 'heycarsten@gmail.com'
6
+ s.homepage = 'http://github.com/heycarsten/bakery'
7
+ s.description = 'A library that aims to simplify the process of turning fragments of LaTeX into images and other formats.'
8
+ s.authors = ['Carsten Nielsen']
9
+ s.files = %w[
10
+ History.txt
11
+ README.txt
12
+ Rakefile
13
+ bakery.gemspec
14
+ lib/bakery.rb
15
+ lib/bakery/command.rb
16
+ lib/bakery/transformation.rb ]
17
+ s.test_files = %w[
18
+ test/test_bakery.rb ]
19
+ s.rdoc_options = %w[ --main README.txt ]
20
+ s.extra_rdoc_files = %w[
21
+ History.txt
22
+ Manifest.txt
23
+ README.txt ]
24
+ end
@@ -0,0 +1,19 @@
1
+ $:.unshift File.dirname(__FILE__) # Used when not installed as gem.
2
+
3
+ require 'open3'
4
+ require 'tempfile'
5
+
6
+ require 'bakery/command'
7
+ require 'bakery/transformation'
8
+
9
+
10
+ module Bakery
11
+
12
+ class Error < StandardError; end
13
+ class MissingSystemDependencyError < Error; end
14
+ class ShellCommandCallError < Error; end
15
+
16
+ VERSION = '0.0.1'
17
+ COMMANDS = [:latex, :dvipng].inject({}) { |h,n| h.merge(n => Command.new(n)) }
18
+
19
+ end
@@ -0,0 +1,75 @@
1
+ module Bakery
2
+
3
+ class Command
4
+
5
+ attr_reader :result, :name
6
+
7
+ def initialize(name)
8
+ raise ArgumentError, 'name must be specified' if '' == name.to_s
9
+ @name = name.to_s
10
+ @result = {
11
+ :out => nil,
12
+ :err => nil }
13
+ check_for_dependency!
14
+ end
15
+
16
+ def check_for_dependency!
17
+ return true unless '' == `which #{name}`.strip
18
+ raise MissingSystemDependencyError, "The command line tool #{name} " +
19
+ 'does not appear to exist on this system, have you installed teTeX?'
20
+ end
21
+
22
+ def to_command(*options)
23
+ [name, transform_options(options)].join(' ')
24
+ end
25
+
26
+ def exec(*options)
27
+ command = to_command(options)
28
+ Open3.popen3(command) do |_, stdout, stderr|
29
+ result[:out] = stdout.readlines.join("\n")
30
+ result[:err] = stderr.readlines.join("\n")
31
+ end
32
+ return result[:out] if '' == result[:err].strip
33
+ raise ShellCommandCallError, "The command: #{command} failed to " +
34
+ "execute properly. The output was:\n\n#{result[:out]}\n\nThe error " +
35
+ "output was:\n\n#{result[:err]}"
36
+ end
37
+
38
+ protected
39
+
40
+ def transform_options(options_array)
41
+ options_array.flatten.inject([]) do |opts, item|
42
+ opts << if Hash === item
43
+ transform_options_hash item
44
+ else
45
+ transform_option_name item
46
+ end
47
+ end
48
+ end
49
+
50
+ def transform_options_hash(options_hash)
51
+ options_hash.inject([]) do |opts, (key, value)|
52
+ opt_name = transform_option_name(key)
53
+ opt_value = transform_option_value(value)
54
+ opts << combine_option_name_and_value(opt_name, opt_value)
55
+ end
56
+ end
57
+
58
+ def transform_option_name(value)
59
+ name = value.to_s
60
+ raise ArgumentError, 'value can not be blank!' if '' == name
61
+ (1 == name.length) ? "-#{name}" : "--#{name.gsub('_', '-')}"
62
+ end
63
+
64
+ def transform_option_value(value)
65
+ (String === value) ? "'#{value}'" : value.to_s
66
+ end
67
+
68
+ def combine_option_name_and_value(name, value)
69
+ return name if value.nil? || '' == value
70
+ (2 == name.length) ? "#{name} #{value}" : "#{name}=#{value}"
71
+ end
72
+
73
+ end
74
+
75
+ end
@@ -0,0 +1,6 @@
1
+ module Bakery
2
+
3
+ class Transformation
4
+ end
5
+
6
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: heycarsten-bakery
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Carsten Nielsen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-10-27 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: A library that aims to simplify the process of turning fragments of LaTeX into images and other formats.
17
+ email: heycarsten@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - History.txt
24
+ - Manifest.txt
25
+ - README.txt
26
+ files:
27
+ - History.txt
28
+ - README.txt
29
+ - Rakefile
30
+ - bakery.gemspec
31
+ - lib/bakery.rb
32
+ - lib/bakery/command.rb
33
+ - lib/bakery/transformation.rb
34
+ - Manifest.txt
35
+ has_rdoc: false
36
+ homepage: http://github.com/heycarsten/bakery
37
+ post_install_message:
38
+ rdoc_options:
39
+ - --main
40
+ - README.txt
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ version:
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ requirements: []
56
+
57
+ rubyforge_project:
58
+ rubygems_version: 1.2.0
59
+ signing_key:
60
+ specification_version: 2
61
+ summary: A library for turning fragments of LaTeX into images
62
+ test_files:
63
+ - test/test_bakery.rb