rtex 1.99.0

Sign up to get free protection for your applications and to get access to all the features.
data/tasks/setup.rb ADDED
@@ -0,0 +1,205 @@
1
+ # $Id$
2
+
3
+ require 'rubygems'
4
+ require 'rake'
5
+ require 'rake/clean'
6
+ require 'fileutils'
7
+ require 'ostruct'
8
+
9
+ PROJ = OpenStruct.new
10
+
11
+ PROJ.name = nil
12
+ PROJ.summary = nil
13
+ PROJ.description = nil
14
+ PROJ.changes = nil
15
+ PROJ.authors = nil
16
+ PROJ.email = nil
17
+ PROJ.url = nil
18
+ PROJ.version = ENV['VERSION'] || '0.0.0'
19
+ PROJ.rubyforge_name = nil
20
+ PROJ.exclude = %w(tmp$ bak$ ~$ CVS site .svn/ ^pkg/ ^doc/ ^\. ^rails-example/)
21
+ PROJ.release_name = ENV['RELEASE']
22
+ PROJ.history_file = 'HISTORY.rdoc'
23
+ PROJ.manifest_file = 'Manifest.txt'
24
+ PROJ.readme_file = 'README.rdoc'
25
+
26
+ # Test::Unit
27
+ PROJ.tests = FileList['test/**/*_test.rb']
28
+ PROJ.test_file = 'test/all.rb'
29
+ PROJ.test_opts = []
30
+
31
+ # Rcov
32
+ PROJ.rcov_dir = 'coverage'
33
+ PROJ.rcov_opts = ['--sort', 'coverage', '-T']
34
+ PROJ.rcov_threshold = 90.0
35
+ PROJ.rcov_threshold_exact = false
36
+
37
+ # Rdoc
38
+ PROJ.rdoc_opts = []
39
+ PROJ.rdoc_include = %w(^lib/ ^bin/ ^ext/ .txt$)
40
+ PROJ.rdoc_exclude = %w(extconf.rb$)
41
+ PROJ.rdoc_main = nil
42
+ PROJ.rdoc_dir = 'doc'
43
+ PROJ.rdoc_remote_dir = nil
44
+
45
+ # Gem Packaging
46
+ PROJ.files = nil
47
+ PROJ.executables = nil
48
+ PROJ.dependencies = []
49
+ PROJ.need_tar = true
50
+ PROJ.need_zip = false
51
+ PROJ.post_install_message = nil
52
+
53
+ # Announce
54
+ PROJ.ann_file = 'announcement.txt'
55
+ PROJ.ann_text = nil
56
+ PROJ.ann_paragraphs = []
57
+ PROJ.ann_email = {
58
+ :from => nil,
59
+ :to => %w(ruby-talk@ruby-lang.org),
60
+ :server => 'localhost',
61
+ :port => 25,
62
+ :domain => ENV['HOSTNAME'],
63
+ :acct => nil,
64
+ :passwd => nil,
65
+ :authtype => :plain
66
+ }
67
+
68
+ # Load the other rake files in the tasks folder
69
+ rakefiles = Dir.glob('tasks/*.rake').sort
70
+ rakefiles.unshift(rakefiles.delete('tasks/post_load.rake')).compact!
71
+ import(*rakefiles)
72
+
73
+ # Setup some constants
74
+ WIN32 = %r/djgpp|(cyg|ms|bcc)win|mingw/ =~ RUBY_PLATFORM unless defined? WIN32
75
+
76
+ DEV_NULL = WIN32 ? 'NUL:' : '/dev/null'
77
+
78
+ def quiet( &block )
79
+ io = [STDOUT.dup, STDERR.dup]
80
+ STDOUT.reopen DEV_NULL
81
+ STDERR.reopen DEV_NULL
82
+ block.call
83
+ ensure
84
+ STDOUT.reopen io.first
85
+ STDERR.reopen io.last
86
+ end
87
+
88
+ DIFF = if WIN32 then 'diff.exe'
89
+ else
90
+ if quiet {system "gdiff", __FILE__, __FILE__} then 'gdiff'
91
+ else 'diff' end
92
+ end unless defined? DIFF
93
+
94
+ SUDO = if WIN32 then ''
95
+ else
96
+ if quiet {system 'which sudo'} then 'sudo'
97
+ else '' end
98
+ end
99
+
100
+ RCOV = WIN32 ? 'rcov.bat' : 'rcov'
101
+ GEM = WIN32 ? 'gem.bat' : 'gem'
102
+
103
+ %w(rcov spec/rake/spectask rubyforge bones facets/ansicode).each do |lib|
104
+ begin
105
+ require lib
106
+ Object.instance_eval {const_set "HAVE_#{lib.tr('/','_').upcase}", true}
107
+ rescue LoadError
108
+ Object.instance_eval {const_set "HAVE_#{lib.tr('/','_').upcase}", false}
109
+ end
110
+ end
111
+
112
+ # Reads a file at +path+ and spits out an array of the +paragraphs+
113
+ # specified.
114
+ #
115
+ # changes = paragraphs_of('History.txt', 0..1).join("\n\n")
116
+ # summary, *description = paragraphs_of('README.txt', 3, 3..8)
117
+ #
118
+ def paragraphs_of( path, *paragraphs )
119
+ title = String === paragraphs.first ? paragraphs.shift : nil
120
+ ary = File.read(path).delete("\r").split(/\n\n+/)
121
+
122
+ result = if title
123
+ tmp, matching = [], false
124
+ rgxp = %r/^=+\s*#{Regexp.escape(title)}/i
125
+ paragraphs << (0..-1) if paragraphs.empty?
126
+
127
+ ary.each do |val|
128
+ if val =~ rgxp
129
+ break if matching
130
+ matching = true
131
+ rgxp = %r/^=+/i
132
+ elsif matching
133
+ tmp << val
134
+ end
135
+ end
136
+ tmp
137
+ else ary end
138
+
139
+ result.values_at(*paragraphs)
140
+ end
141
+
142
+ # Adds the given gem _name_ to the current project's dependency list. An
143
+ # optional gem _version_ can be given. If omitted, the newest gem version
144
+ # will be used.
145
+ #
146
+ def depend_on( name, version = nil )
147
+ spec = Gem.source_index.find_name(name).last
148
+ version = spec.version.to_s if version.nil? and !spec.nil?
149
+
150
+ PROJ.dependencies << case version
151
+ when nil; [name]
152
+ when %r/^\d/; [name, ">= #{version}"]
153
+ else [name, version] end
154
+ end
155
+
156
+ # Adds the given arguments to the include path if they are not already there
157
+ #
158
+ def ensure_in_path( *args )
159
+ args.each do |path|
160
+ path = File.expand_path(path)
161
+ $:.unshift(path) if test(?d, path) and not $:.include?(path)
162
+ end
163
+ end
164
+
165
+ # Find a rake task using the task name and remove any description text. This
166
+ # will prevent the task from being displayed in the list of available tasks.
167
+ #
168
+ def remove_desc_for_task( names )
169
+ Array(names).each do |task_name|
170
+ task = Rake.application.tasks.find {|t| t.name == task_name}
171
+ next if task.nil?
172
+ task.instance_variable_set :@comment, nil
173
+ end
174
+ end
175
+
176
+ # Change working directories to _dir_, call the _block_ of code, and then
177
+ # change back to the original working directory (the current directory when
178
+ # this method was called).
179
+ #
180
+ def in_directory( dir, &block )
181
+ curdir = pwd
182
+ begin
183
+ cd dir
184
+ return block.call
185
+ ensure
186
+ cd curdir
187
+ end
188
+ end
189
+
190
+ # Scans the current working directory and creates a list of files that are
191
+ # candidates to be in the manifest.
192
+ #
193
+ def manifest_files
194
+ files = []
195
+ exclude = Regexp.new(PROJ.exclude.join('|'))
196
+ Find.find '.' do |path|
197
+ path.sub! %r/^(\.\/|\/)/o, ''
198
+ next unless test ?f, path
199
+ next if path =~ exclude
200
+ files << path
201
+ end
202
+ files.sort!
203
+ end
204
+
205
+ # EOF
data/tasks/test.rake ADDED
@@ -0,0 +1,38 @@
1
+ # $Id$
2
+
3
+ require 'rake/testtask'
4
+
5
+ namespace :test do
6
+
7
+ Rake::TestTask.new(:run) do |t|
8
+ t.libs = PROJ.libs
9
+ t.test_files = if test(?f, PROJ.test_file) then [PROJ.test_file]
10
+ else PROJ.tests end
11
+ t.ruby_opts += PROJ.ruby_opts
12
+ t.ruby_opts += PROJ.test_opts
13
+ end
14
+
15
+ if HAVE_RCOV
16
+ desc 'Run rcov on the unit tests'
17
+ task :rcov => :clobber_rcov do
18
+ opts = PROJ.rcov_opts.dup << '-o' << PROJ.rcov_dir
19
+ opts = opts.join(' ')
20
+ files = if test(?f, PROJ.test_file) then [PROJ.test_file]
21
+ else PROJ.tests end
22
+ files = files.join(' ')
23
+ sh "#{RCOV} #{files} #{opts}"
24
+ end
25
+
26
+ task :clobber_rcov do
27
+ rm_r 'coverage' rescue nil
28
+ end
29
+ end
30
+
31
+ end # namespace :test
32
+
33
+ desc 'Alias to test:run'
34
+ task :test => 'test:run'
35
+
36
+ task :clobber => 'test:clobber_rcov' if HAVE_RCOV
37
+
38
+ # EOF
@@ -0,0 +1,70 @@
1
+ require File.dirname(__FILE__) << '/test_helper'
2
+
3
+ context "Document Generation" do
4
+
5
+ def setup
6
+ change_tmpdir_for_testing
7
+ end
8
+
9
+ specify "documents have a to_pdf method" do
10
+ assert document(:first).respond_to?(:to_pdf)
11
+ end
12
+
13
+ specify "can escape characters" do
14
+ assert_equal '\textbackslash{}\textasciitilde{}', RTeX::Document.escape('\~')
15
+ end
16
+
17
+ specify "documents can use a to_pdf block to move a file to a relative path" do
18
+ begin
19
+ path = File.expand_path(File.dirname(__FILE__) << '/tmp/this_is_relative_to_pwd.pdf')
20
+ document(:first).to_pdf do |filename|
21
+ assert_nothing_raised do
22
+ FileUtils.move filename, path
23
+ end
24
+ assert File.exists?(path)
25
+ end
26
+ ensure
27
+ FileUtils.rm path rescue nil
28
+ end
29
+ end
30
+
31
+ specify "can generate PDF and return as a string" do
32
+ @author = 'Foo'
33
+ assert_equal '%PDF', document(:first).to_pdf(binding)[0, 4]
34
+ end
35
+
36
+ specify "can generate TeX source and return as a string with debug option" do
37
+ @author = 'Foo'
38
+ assert_not_equal '%PDF', document(:first, :tex => true).to_pdf(binding)[0, 4]
39
+ end
40
+
41
+ specify "can generate PDF and give access to file directly" do
42
+ @author = 'Foo'
43
+ data_read = nil
44
+ invocation_result = document(:first).to_pdf(binding) do |filename|
45
+ data_read = File.open(filename, 'rb') { |f| f.read }
46
+ :not_the_file_contents
47
+ end
48
+ assert_equal '%PDF', data_read[0, 4]
49
+ assert_equal :not_the_file_contents, invocation_result
50
+ end
51
+
52
+ specify "can generate TeX source and give access to file directly" do
53
+ @author = 'Foo'
54
+ data_read = nil
55
+ invocation_result = document(:first, :tex => true).to_pdf(binding) do |filename|
56
+ data_read = File.open(filename, 'rb') { |f| f.read }
57
+ :not_the_file_contents
58
+ end
59
+ assert_not_equal '%PDF', data_read[0, 4]
60
+ assert_equal :not_the_file_contents, invocation_result
61
+ end
62
+
63
+ specify "can wrap in a layout using `yield'" do
64
+ doc = document(:fragment, :layout => 'testing_layout[<%= yield %>]')
65
+ @name = 'ERB'
66
+ source = doc.source(binding)
67
+ assert source =~ /^testing_layout.*?ERB, Fragmented/
68
+ end
69
+
70
+ end
@@ -0,0 +1,20 @@
1
+ require File.dirname(__FILE__) << '/test_helper'
2
+
3
+ context "Filtering Documents" do
4
+
5
+ specify "can filter through textile" do
6
+ doc = document('text.textile', :filter => 'textile')
7
+ source = doc.source(binding)
8
+ assert source.include?('\item')
9
+ end
10
+
11
+ specify "does not affect layouts" do
12
+ doc = document('text.textile',
13
+ :filter => 'textile',
14
+ :layout => "* layout\n* is\n<%= yield %>")
15
+ source = doc.source(binding)
16
+ assert source.include?("* layout"), "filtered layout"
17
+ assert source.include?('\item'), "didn't filter content"
18
+ end
19
+
20
+ end
@@ -0,0 +1,50 @@
1
+ % This percent indicates a comment.
2
+ % This is a very simple latex article that introduces the way
3
+ % equations are typeset. Do this in linux:
4
+ %
5
+ % latex first.tex
6
+ % latex first.tex
7
+ % xdvi first.dvi
8
+ % dvips -o first.ps first.dvi
9
+ % gv first.ps
10
+ % lpr first.ps
11
+ % pdflatex first.tex
12
+ % acroread first.pdf
13
+ \documentclass[12pt]{article}
14
+ \title{First \LaTeX}
15
+ \author{Joe Student}
16
+ \date{\today}
17
+
18
+ \begin{document}
19
+
20
+ \maketitle
21
+
22
+ \abstract{This is a very simple example of using \LaTeX\ for typesetting.
23
+ The procedure for typesetting equations is introduced.}
24
+ \begin{sdsd}
25
+ \end{bar}
26
+
27
+ \section{A few equations}
28
+ Equations can be typeset inline like so: $\vec{F}=m\vec{a}$ .
29
+ Equations can also be separated form the text: $$ \vec{F}=m\vec{a} \ . $$
30
+ Notice the punctuation, the ``.'', had to be included with the equation.
31
+ Equations can also have a number assigned and a label attached,
32
+ as in the following:
33
+ \begin{equation}
34
+ \frac{D\vec{\omega}}{Dt} =
35
+ ( \vec{\omega} + \vec{\Omega}) \cdot \nabla \vec{U}
36
+ + \frac{1}{\rho^2} \nabla \rho \times \nabla p
37
+ + \nu \nabla^2 \vec{\omega}
38
+ \label{vorteq}
39
+ \end{equation}
40
+ The vorticity equation (\ref{vorteq}) is referenced by label,
41
+ not by number. The numbers may change as the document grows and
42
+ more equations are added.
43
+
44
+ New paragraphs are indicated with a blank line in the source code.
45
+
46
+ \section{The End}
47
+
48
+ Further examples of \LaTeX\ can be found at {\tt it.metr.ou.edu}
49
+
50
+ \end{document}
@@ -0,0 +1,48 @@
1
+ % This percent indicates a comment.
2
+ % This is a very simple latex article that introduces the way
3
+ % equations are typeset. Do this in linux:
4
+ %
5
+ % latex first.tex
6
+ % latex first.tex
7
+ % xdvi first.dvi
8
+ % dvips -o first.ps first.dvi
9
+ % gv first.ps
10
+ % lpr first.ps
11
+ % pdflatex first.tex
12
+ % acroread first.pdf
13
+ \documentclass[12pt]{article}
14
+ \title{First \LaTeX}
15
+ \author{<%= @author %>}
16
+ \date{\today}
17
+
18
+ \begin{document}
19
+
20
+ \maketitle
21
+
22
+ \abstract{This is a very simple example of using \LaTeX\ for typesetting.
23
+ The procedure for typesetting equations is introduced.}
24
+
25
+ \section{A few equations}
26
+ Equations can be typeset inline like so: $\vec{F}=m\vec{a}$ .
27
+ Equations can also be separated form the text: $$ \vec{F}=m\vec{a} \ . $$
28
+ Notice the punctuation, the ``.'', had to be included with the equation.
29
+ Equations can also have a number assigned and a label attached,
30
+ as in the following:
31
+ \begin{equation}
32
+ \frac{D\vec{\omega}}{Dt} =
33
+ ( \vec{\omega} + \vec{\Omega}) \cdot \nabla \vec{U}
34
+ + \frac{1}{\rho^2} \nabla \rho \times \nabla p
35
+ + \nu \nabla^2 \vec{\omega}
36
+ \label{vorteq}
37
+ \end{equation}
38
+ The vorticity equation (\ref{vorteq}) is referenced by label,
39
+ not by number. The numbers may change as the document grows and
40
+ more equations are added.
41
+
42
+ New paragraphs are indicated with a blank line in the source code.
43
+
44
+ \section{The End}
45
+
46
+ Further examples of \LaTeX\ can be found at {\tt it.metr.ou.edu}
47
+
48
+ \end{document}
@@ -0,0 +1 @@
1
+ \par <%= @name %>, Fragmented
@@ -0,0 +1,4 @@
1
+ This is a list:
2
+ * One
3
+ * Two
4
+ * _three_