texvc 0.1.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ == 0.1.0 / 2008-07-19
2
+
3
+ * initial release
4
+
data/README ADDED
@@ -0,0 +1,36 @@
1
+
2
+ = texvc
3
+
4
+ The wrapper utility for texvc command
5
+
6
+ == Description
7
+
8
+ You can get the rendered image of an mathematical expression through this
9
+ utility.
10
+
11
+ == Installation
12
+
13
+ You need to install texvc command before using this utility.
14
+ The command typically belongs to the package of mediawiki-math.
15
+
16
+ === Archive Installation
17
+
18
+ rake install
19
+
20
+ === Gem Installation
21
+
22
+ gem install texvc
23
+
24
+
25
+ == Features/Problems
26
+
27
+
28
+ == Synopsis
29
+
30
+ Texvc.parse('y=x^2') # => an instance of Magick::Image
31
+
32
+ == Copyright
33
+
34
+ Author:: Genki Takiuchi <genki@s21g.com>
35
+ Copyright:: Copyright (c) 2008 Genki Takiuchi
36
+ License::
@@ -0,0 +1,146 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/clean'
4
+ require 'rake/testtask'
5
+ require 'rake/packagetask'
6
+ require 'rake/gempackagetask'
7
+ require 'rake/rdoctask'
8
+ require 'rake/contrib/rubyforgepublisher'
9
+ require 'rake/contrib/sshpublisher'
10
+ require 'fileutils'
11
+ require 'lib/texvc'
12
+ include FileUtils
13
+
14
+ NAME = "texvc"
15
+ AUTHOR = "Genki Takiuchi"
16
+ EMAIL = "genki@s21g.com"
17
+ DESCRIPTION = "The wrapper utility for texvc command"
18
+ RUBYFORGE_PROJECT = "cocktail-party"
19
+ HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
20
+ BIN_FILES = %w( )
21
+ VERS = Texvc::VERSION
22
+
23
+ REV = File.read(".svn/entries")[/committed-rev="(d+)"/, 1] rescue nil
24
+ CLEAN.include ['**/.*.sw?', '*.gem', '.config']
25
+ RDOC_OPTS = [
26
+ '--title', "#{NAME} documentation",
27
+ "--charset", "utf-8",
28
+ "--opname", "index.html",
29
+ "--line-numbers",
30
+ "--main", "README",
31
+ "--inline-source",
32
+ ]
33
+
34
+ task :default => [:test]
35
+ task :package => [:clean]
36
+
37
+ Rake::TestTask.new("test") do |t|
38
+ t.libs << "test"
39
+ t.pattern = "test/**/*_test.rb"
40
+ t.verbose = true
41
+ end
42
+
43
+ spec = Gem::Specification.new do |s|
44
+ s.name = NAME
45
+ s.version = VERS
46
+ s.platform = Gem::Platform::RUBY
47
+ s.has_rdoc = true
48
+ s.extra_rdoc_files = ["README", "ChangeLog"]
49
+ s.rdoc_options += RDOC_OPTS + ['--exclude', '^(examples|extras)/']
50
+ s.summary = DESCRIPTION
51
+ s.description = DESCRIPTION
52
+ s.author = AUTHOR
53
+ s.email = EMAIL
54
+ s.homepage = HOMEPATH
55
+ s.executables = BIN_FILES
56
+ s.rubyforge_project = RUBYFORGE_PROJECT
57
+ s.bindir = "bin"
58
+ s.require_path = "lib"
59
+ s.autorequire = ""
60
+ s.test_files = Dir["test/*_test.rb"]
61
+
62
+ s.add_dependency('escape', '>=0.0.4')
63
+ s.add_dependency('rmagick')
64
+ s.add_dependency('tempdir')
65
+ s.add_dependency('redgreen', '>=1.2.2')
66
+ #s.required_ruby_version = '>= 1.8.2'
67
+
68
+ s.files = %w(README ChangeLog Rakefile) +
69
+ Dir.glob("{bin,doc,test,lib,templates,generator,extras,website,script}/**/*") +
70
+ Dir.glob("ext/**/*.{h,c,rb}") +
71
+ Dir.glob("examples/**/*.rb") +
72
+ Dir.glob("tools/*.rb")
73
+
74
+ s.extensions = FileList["ext/**/extconf.rb"].to_a
75
+ end
76
+
77
+ Rake::GemPackageTask.new(spec) do |p|
78
+ p.need_tar = true
79
+ p.gem_spec = spec
80
+ end
81
+
82
+ task :install do
83
+ name = "#{NAME}-#{VERS}.gem"
84
+ sh %{rake package}
85
+ sh %{sudo gem install pkg/#{name}}
86
+ end
87
+
88
+ task :uninstall => [:clean] do
89
+ sh %{sudo gem uninstall #{NAME}}
90
+ end
91
+
92
+
93
+ Rake::RDocTask.new do |rdoc|
94
+ rdoc.rdoc_dir = 'html'
95
+ rdoc.options += RDOC_OPTS
96
+ rdoc.template = "resh"
97
+ #rdoc.template = "#{ENV['template']}.rb" if ENV['template']
98
+ if ENV['DOC_FILES']
99
+ rdoc.rdoc_files.include(ENV['DOC_FILES'].split(/,\s*/))
100
+ else
101
+ rdoc.rdoc_files.include('README', 'ChangeLog')
102
+ rdoc.rdoc_files.include('lib/**/*.rb')
103
+ rdoc.rdoc_files.include('ext/**/*.c')
104
+ end
105
+ end
106
+
107
+ desc "Publish to RubyForge"
108
+ task :rubyforge => [:rdoc, :package] do
109
+ require 'rubyforge'
110
+ Rake::RubyForgePublisher.new(RUBYFORGE_PROJECT, 'takiuchi').upload
111
+ end
112
+
113
+ desc 'Package and upload the release to rubyforge.'
114
+ task :release => [:clean, :package] do |t|
115
+ v = ENV["VERSION"] or abort "Must supply VERSION=x.y.z"
116
+ abort "Versions don't match #{v} vs #{VERS}" unless v == VERS
117
+ pkg = "pkg/#{NAME}-#{VERS}"
118
+
119
+ require 'rubyforge'
120
+ rf = RubyForge.new.configure
121
+ puts "Logging in"
122
+ rf.login
123
+
124
+ c = rf.userconfig
125
+ # c["release_notes"] = description if description
126
+ # c["release_changes"] = changes if changes
127
+ c["preformatted"] = true
128
+
129
+ files = [
130
+ "#{pkg}.tgz",
131
+ "#{pkg}.gem"
132
+ ].compact
133
+
134
+ puts "Releasing #{NAME} v. #{VERS}"
135
+ rf.add_release RUBYFORGE_PROJECT, NAME, VERS, *files
136
+ end
137
+
138
+ desc 'Show information about the gem.'
139
+ task :debug_gem do
140
+ puts spec.to_ruby
141
+ end
142
+
143
+ desc 'Update gem spec'
144
+ task :gemspec do
145
+ open("#{NAME}.gemspec", 'w').write spec.to_ruby
146
+ end
@@ -0,0 +1,52 @@
1
+ require 'RMagick'
2
+ require 'escape'
3
+ require 'temp_dir'
4
+
5
+ module Texvc
6
+ VERSION = '0.1.1.1'
7
+
8
+ class SyntaxError < StandardError; end
9
+ class LexingError < StandardError; end
10
+ class UnknownFunctionError < StandardError; end
11
+ class UnknownError < StandardError; end
12
+
13
+ class << self
14
+ def parse(latex, options = {})
15
+ image = nil
16
+ latex = "{}_{#{latex}}" if options[:inline]
17
+
18
+ TempDir.create :basename => 'texvc' do |tmp|
19
+ cmd = Escape.shell_command(['texvc', tmp, tmp, latex, 'utf8'])
20
+ result = nil
21
+ IO.popen(%Q{#{cmd.to_s} 2>/dev/null}, 'r+') do |io|
22
+ io.puts latex rescue nil
23
+ result = io.gets
24
+ end
25
+
26
+ path = File.join(tmp, "#{result[1, 32]}.png")
27
+
28
+ image = case result[0]
29
+ when ?+; read_image(path)
30
+ when ?c; read_image(path)
31
+ when ?m; read_image(path)
32
+ when ?l; read_image(path)
33
+ when ?C; read_image(path)
34
+ when ?M; read_image(path)
35
+ when ?L; read_image(path)
36
+ when ?X; read_image(path)
37
+ when ?S; raise SyntaxError.new
38
+ when ?E; raise LexingError.new
39
+ when ?F; raise UnknownFunctionError.new(result[1..-1])
40
+ else raise UnknownError.new(result)
41
+ end
42
+ end
43
+
44
+ image
45
+ end
46
+
47
+ private
48
+ def read_image(path)
49
+ Magick::Image.from_blob(open(path).read)[0]# rescue nil
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,5 @@
1
+ require 'test/unit'
2
+ require 'rubygems'
3
+ require File.dirname(__FILE__) + '/../lib/texvc'
4
+ require 'redgreen'
5
+
@@ -0,0 +1,16 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ require "test/unit"
4
+ class TexvcTest < Test::Unit::TestCase
5
+ def test_generate_image
6
+ image = Texvc.parse('y=x^2')
7
+ assert_not_nil image
8
+ assert_equal Magick::Image, image.class
9
+ end
10
+
11
+ def test_invalid_latex
12
+ assert_raise Texvc::UnknownFunctionError do
13
+ Texvc.parse('\foo')
14
+ end
15
+ end
16
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: texvc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Genki Takiuchi
8
+ autorequire: ""
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-07-21 00:00:00 +09:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: escape
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.4
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: rmagick
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: tempdir
37
+ type: :runtime
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ version:
45
+ - !ruby/object:Gem::Dependency
46
+ name: redgreen
47
+ type: :runtime
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 1.2.2
54
+ version:
55
+ description: The wrapper utility for texvc command
56
+ email: genki@s21g.com
57
+ executables: []
58
+
59
+ extensions: []
60
+
61
+ extra_rdoc_files:
62
+ - README
63
+ - ChangeLog
64
+ files:
65
+ - README
66
+ - ChangeLog
67
+ - Rakefile
68
+ - test/test_helper.rb
69
+ - test/texvc_test.rb
70
+ - lib/texvc.rb
71
+ has_rdoc: true
72
+ homepage: http://cocktail-party.rubyforge.org
73
+ post_install_message:
74
+ rdoc_options:
75
+ - --title
76
+ - texvc documentation
77
+ - --charset
78
+ - utf-8
79
+ - --opname
80
+ - index.html
81
+ - --line-numbers
82
+ - --main
83
+ - README
84
+ - --inline-source
85
+ - --exclude
86
+ - ^(examples|extras)/
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: "0"
94
+ version:
95
+ required_rubygems_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: "0"
100
+ version:
101
+ requirements: []
102
+
103
+ rubyforge_project: cocktail-party
104
+ rubygems_version: 1.2.0
105
+ signing_key:
106
+ specification_version: 2
107
+ summary: The wrapper utility for texvc command
108
+ test_files:
109
+ - test/texvc_test.rb