condom 0.2.0 → 1.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.
- data/CHANGELOG.rdoc +6 -0
- data/README.rdoc +24 -17
- data/bin/condom +82 -53
- data/lib/condom.rb +6 -1
- data/lib/condom/base.rb +9 -9
- data/lib/condom/document.rb +1 -1
- data/lib/condom/letter.rb +1 -1
- data/lib/condom/presentation.rb +2 -2
- metadata +3 -3
data/CHANGELOG.rdoc
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
== 1.0.0
|
2
|
+
|
3
|
+
* Rewrote the executable, it is now simpler and allow user to change every fields (see the README).
|
4
|
+
* Renamed 'outputdir' attribute to 'directory'.
|
5
|
+
* Changed syntax according to 1.9.* Ruby versions (e.g. ':' in case), **but still doesn't work on 1.9.* Ruby versions!**
|
6
|
+
|
1
7
|
== 0.2.0
|
2
8
|
|
3
9
|
* Changed files organisation: specific documents now extend a Base class.
|
data/README.rdoc
CHANGED
@@ -28,29 +28,36 @@ This command needs Rubygems (rubygems package on Ubuntu).
|
|
28
28
|
|
29
29
|
=== Executable
|
30
30
|
|
31
|
-
Condom gem provides a condom shell command.
|
31
|
+
Condom gem provides a 'condom' shell command.
|
32
32
|
|
33
33
|
$ condom --help
|
34
|
-
Usage: condom [
|
34
|
+
Usage: condom [type] [options]
|
35
|
+
|
36
|
+
Available types:
|
37
|
+
document 'article', 'report' or other classes
|
38
|
+
presentation 'beamer' class
|
39
|
+
letter 'letter' class
|
35
40
|
|
36
41
|
Available options:
|
37
|
-
-m, --math Math packages
|
38
|
-
-l, --listings Listings package
|
39
|
-
-f, --fancyhdr Fancyhdr package
|
40
|
-
-p, --pdf PDF config
|
41
|
-
-g, --graphics Images packages
|
42
42
|
-n, --filename=FILENAME Define a file name
|
43
43
|
-a, --author=AUTHOR Define the author
|
44
44
|
-t, --title=TITLE Define the title
|
45
45
|
-d, --date=DATE Define the date
|
46
|
-
-c, --class=CLASS
|
47
|
-
|
48
|
-
-
|
49
|
-
-
|
46
|
+
-c, --document-class=CLASS Define the document class
|
47
|
+
-l, --language=LANGUAGE Define the language
|
48
|
+
-p, --package=PACKAGE Add another package
|
49
|
+
-o, --directory=DIRECTORY Define the output directory
|
50
|
+
-q, --quiet Don't ask any question
|
50
51
|
-v, --version Print Condom version
|
51
52
|
|
52
|
-
|
53
|
-
|
53
|
+
For example, you can easily generate a set of files for a presentation in a folder named 'My Presentation' using:
|
54
|
+
|
55
|
+
condom presentation -o "My Presentation"
|
56
|
+
|
57
|
+
Unless the --quiet option is used, every options will be prompted for confirmation until the validation of the user (the type will be prompted just one time).
|
58
|
+
|
59
|
+
In generated files, there is a Makefile (see the Technique section below for more information about the file organization).
|
60
|
+
Just use your document (from the source folder) with the following commands.
|
54
61
|
|
55
62
|
compile with:
|
56
63
|
$ make
|
@@ -84,7 +91,7 @@ All constructors of these classes will use default values, but also accept:
|
|
84
91
|
* a Hash of options. Keys of the options hash should be symbols with the same name than the attributes of the class.
|
85
92
|
i.e.:
|
86
93
|
|
87
|
-
doc = Condom::Document.new(:document_class => "report", :math => true, :
|
94
|
+
doc = Condom::Document.new(:document_class => "report", :math => true, :directory => "here")
|
88
95
|
|
89
96
|
You can get all options with:
|
90
97
|
|
@@ -99,14 +106,14 @@ Then, once your document is ready to be generated, create it with:
|
|
99
106
|
|
100
107
|
doc.create
|
101
108
|
|
102
|
-
This method will generate all files in the
|
109
|
+
This method will generate all files in the output directory.
|
103
110
|
|
104
111
|
== Technique
|
105
112
|
|
106
113
|
The following command:
|
107
|
-
$ condom
|
114
|
+
$ condom document -t "Condom makes LaTeX easier" -o here
|
108
115
|
|
109
|
-
|
116
|
+
may result the creation of these folders/files:
|
110
117
|
$ tree here/
|
111
118
|
here/
|
112
119
|
├── fig
|
data/bin/condom
CHANGED
@@ -1,74 +1,103 @@
|
|
1
1
|
# Command line tool for Condom
|
2
|
-
#
|
3
|
-
|
4
|
-
#
|
5
|
-
#lib_dir = File.join(File.dirname(__FILE__), '..', 'lib')
|
6
|
-
#$LOAD_PATH.unshift lib_dir unless $LOAD_PATH.include? lib_dir
|
2
|
+
#
|
3
|
+
# Author:: Vivien 'v0n' Didelot <vivien.didelot@gmail.com>
|
4
|
+
# See:: http://github.com/v0n/condom
|
7
5
|
|
8
6
|
require 'condom'
|
9
7
|
require 'optparse'
|
10
8
|
|
11
|
-
|
12
|
-
|
9
|
+
quiet = false
|
10
|
+
types = ['document', 'presentation', 'letter']
|
11
|
+
ops = {:other_packages => []}
|
13
12
|
|
14
13
|
ARGV.options do |o|
|
15
|
-
o.banner = "Usage: #{File.basename $0} [
|
16
|
-
o.on_head("\nAvailable
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
o.on("-
|
22
|
-
o.on("-
|
23
|
-
o.on("-
|
24
|
-
o.on("-
|
25
|
-
o.on("-
|
26
|
-
o.on("-
|
27
|
-
|
28
|
-
o.on("-
|
29
|
-
o.on("-
|
30
|
-
o.on("-v", "--version",
|
14
|
+
o.banner = "Usage: #{File.basename $0} [type] [options]\n"
|
15
|
+
o.on_head("\nAvailable types:",
|
16
|
+
" document 'article', 'report' or other classes",
|
17
|
+
" presentation 'beamer' class",
|
18
|
+
" letter 'letter' class",
|
19
|
+
"\nAvailable options:")
|
20
|
+
o.on("-n", "--filename=FILENAME", String, "Define a file name") { |v| ops[:filename] = v }
|
21
|
+
o.on("-a", "--author=AUTHOR", String, "Define the author") { |v| ops[:author] = v }
|
22
|
+
o.on("-t", "--title=TITLE", String, "Define the title") { |v| ops[:title] = v }
|
23
|
+
o.on("-d", "--date=DATE", String, "Define the date") { |v| ops[:date] = v }
|
24
|
+
o.on("-c", "--document-class=CLASS", String, "Define the document class") { |v| ops[:document_class] = v }
|
25
|
+
o.on("-l", "--language=LANGUAGE", String, "Define the language") { |v| ops[:language] = v }
|
26
|
+
o.on("-p", "--package=PACKAGE", String, "Add another package") { |v| ops[:other_packages].push v }
|
27
|
+
o.on("-o", "--directory=DIRECTORY", String, "Define the output directory") { |v| ops[:directory] = v }
|
28
|
+
o.on("-q", "--quiet", "Don't ask any question") { quiet = true }
|
29
|
+
o.on("-v", "--version", "Print Condom version") { puts "Condom lib: version #{Condom::VERSION}" ; exit }
|
31
30
|
end
|
32
31
|
|
33
32
|
begin
|
34
33
|
ARGV.options.parse!
|
34
|
+
raise "Bad syntax. Try \`#{File.basename $0} --help' for more information." if ARGV.length > 1
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
printf "%-15s=> %s\n", key, value
|
50
|
-
end
|
51
|
-
print "\nContinue [Y/n/h]? "
|
52
|
-
case STDIN.gets.strip
|
53
|
-
when 'Y', 'y', ''
|
54
|
-
when 'h'
|
55
|
-
puts ARGV.options
|
56
|
-
exit
|
36
|
+
if ARGV.size == 1
|
37
|
+
doc = case ARGV.first
|
38
|
+
when 'document' then Condom::Document.new
|
39
|
+
when 'presentation' then Condom::Presentation.new
|
40
|
+
when 'letter' then Condom::Letter.new
|
41
|
+
else raise "Bad syntax. Try \`#{File.basename $0} --help' for more information."
|
42
|
+
end
|
43
|
+
elsif ops.has_key? :document_class
|
44
|
+
doc = case ops[:document_class]
|
45
|
+
when 'beamer' then Condom::Presentation.new
|
46
|
+
when 'letter' then Condom::Letter.new
|
47
|
+
else Condom::Document.new
|
48
|
+
end
|
57
49
|
else
|
58
|
-
|
59
|
-
exit
|
50
|
+
doc = Condom::Document.new
|
60
51
|
end
|
61
52
|
|
62
|
-
doc = case ops[:document_class]
|
63
|
-
when 'beamer': Condom::Presentation.new
|
64
|
-
when 'letter': Condom::Letter.new
|
65
|
-
else Condom::Document.new
|
66
|
-
end
|
67
53
|
doc.set_options(ops)
|
54
|
+
|
55
|
+
unless quiet
|
56
|
+
# Ask for confirmation
|
57
|
+
puts "Enter the new value, or press ENTER for the default"
|
58
|
+
|
59
|
+
doc_type = doc.class.to_s.split('::').last.downcase
|
60
|
+
printf " type [%s]: ", doc_type
|
61
|
+
type = STDIN.gets.strip
|
62
|
+
doc = case type
|
63
|
+
when 'document' then Condom::Document.new(ops)
|
64
|
+
when 'presentation' then Condom::Presentation.new(ops)
|
65
|
+
when 'letter' then Condom::Letter.new(ops)
|
66
|
+
else raise "Bad syntax. Try \`#{File.basename $0} --help' for more information."
|
67
|
+
end unless type.empty? || type == doc_type
|
68
|
+
puts
|
69
|
+
|
70
|
+
loop do
|
71
|
+
ops = Hash.new
|
72
|
+
doc.get_options.each do |key, value|
|
73
|
+
displayed_value = case value
|
74
|
+
when true then "yes"
|
75
|
+
when false then "no"
|
76
|
+
when Array then value.join(', ')
|
77
|
+
else value
|
78
|
+
end
|
79
|
+
printf " %-17s [%s]: ", key, displayed_value
|
80
|
+
new_value = STDIN.gets.strip
|
81
|
+
ops[key] = if value.is_a?(FalseClass) && new_value == "yes" then true
|
82
|
+
elsif value.is_a?(TrueClass) && new_value == "no" then false
|
83
|
+
elsif key == :other_packages then new_value.split(/\s*,\s*/)
|
84
|
+
else new_value
|
85
|
+
end unless new_value.empty?
|
86
|
+
end
|
87
|
+
doc.set_options(ops) unless ops.empty?
|
88
|
+
|
89
|
+
print "\nIs the information correct? [Y/n/q] "
|
90
|
+
case STDIN.gets.strip
|
91
|
+
when /^Y?$/i then break
|
92
|
+
when 'q' then exit
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
68
97
|
doc.create
|
69
|
-
puts "Files created in #{doc.
|
98
|
+
puts "info: Files created in #{doc.directory}."
|
70
99
|
rescue => e
|
71
|
-
STDERR.puts "
|
100
|
+
STDERR.puts "fail: #{e}"
|
72
101
|
end
|
73
102
|
|
74
103
|
exit
|
data/lib/condom.rb
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
# Condom, a Ruby lib for LaTeX document.
|
2
|
+
#
|
3
|
+
# Author:: Vivien 'v0n' Didelot <vivien.didelot@gmail.com>
|
4
|
+
# See:: http://github.com/v0n/condom
|
5
|
+
|
1
6
|
require "condom/base"
|
2
7
|
require "condom/letter"
|
3
8
|
require "condom/document"
|
@@ -7,7 +12,7 @@ require "etc"
|
|
7
12
|
|
8
13
|
module Condom
|
9
14
|
# Lib version
|
10
|
-
VERSION = '0.
|
15
|
+
VERSION = '1.0.0'
|
11
16
|
|
12
17
|
# Constant views directory
|
13
18
|
VIEWS_DIR = File.join(File.expand_path(File.dirname(__FILE__)), 'views')
|
data/lib/condom/base.rb
CHANGED
@@ -9,7 +9,7 @@ module Condom
|
|
9
9
|
# This is the main class of the condom lib.
|
10
10
|
# It will contain all common attributes and methods to every LaTeX document.
|
11
11
|
class Base
|
12
|
-
attr_accessor :
|
12
|
+
attr_accessor :directory, :filename,
|
13
13
|
:author, :title, :date, :document_class, :language,
|
14
14
|
:other_packages
|
15
15
|
|
@@ -20,11 +20,11 @@ module Condom
|
|
20
20
|
# * a hash of options.
|
21
21
|
def initialize(args = nil)
|
22
22
|
# Need to initialize each variables else they won't exist in instance_variables.
|
23
|
-
@
|
23
|
+
@directory = @filename = @author = @title = @date = @document_class = @language = @other_packages = nil
|
24
24
|
|
25
25
|
# The default options
|
26
26
|
set_options({
|
27
|
-
:
|
27
|
+
:directory => Dir.getwd,
|
28
28
|
:filename => 'main',
|
29
29
|
:author => Condom.get_user_name,
|
30
30
|
:title => 'Document \LaTeX',
|
@@ -62,7 +62,7 @@ module Condom
|
|
62
62
|
|
63
63
|
# This method will create in output directory all needed files.
|
64
64
|
def create
|
65
|
-
|
65
|
+
in_directory do
|
66
66
|
raise("Please use a specific Condom class, not Base.")
|
67
67
|
end
|
68
68
|
end
|
@@ -71,14 +71,14 @@ module Condom
|
|
71
71
|
|
72
72
|
# This method creates the output directory (if needed)
|
73
73
|
# and execute the block given in parameter.
|
74
|
-
def
|
74
|
+
def in_directory
|
75
75
|
# Verify output
|
76
|
-
FileUtils.makedirs @
|
76
|
+
FileUtils.makedirs @directory
|
77
77
|
raise(ArgumentError, "A block should be given") unless block_given?
|
78
78
|
|
79
|
-
Dir.chdir @
|
80
|
-
raise("#{@
|
81
|
-
raise("#{@
|
79
|
+
Dir.chdir @directory do
|
80
|
+
raise("#{@directory}: it already exists a main.tex file") if File.exist? "main.tex"
|
81
|
+
raise("#{@directory}: it already exists a Makefile") if File.exist? "Makefile"
|
82
82
|
|
83
83
|
# Call the given instructions block
|
84
84
|
yield
|
data/lib/condom/document.rb
CHANGED
data/lib/condom/letter.rb
CHANGED
data/lib/condom/presentation.rb
CHANGED
@@ -17,7 +17,7 @@ module Condom
|
|
17
17
|
# The default options
|
18
18
|
options = {
|
19
19
|
:document_class => 'beamer',
|
20
|
-
:title => '
|
20
|
+
:title => 'Presentation \LaTeX',
|
21
21
|
:filename => 'presentation',
|
22
22
|
:listings => false,
|
23
23
|
:graphics => true,
|
@@ -35,7 +35,7 @@ module Condom
|
|
35
35
|
|
36
36
|
# This method will write in the output directory all needed files.
|
37
37
|
def create
|
38
|
-
|
38
|
+
in_directory do
|
39
39
|
# Create files
|
40
40
|
build "presentation.tex"
|
41
41
|
File.rename("presentation.tex", "main.tex")
|
metadata
CHANGED
@@ -4,10 +4,10 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
hash: 23
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
|
+
- 1
|
7
8
|
- 0
|
8
|
-
- 2
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 1.0.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Vivien Didelot
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-08-
|
18
|
+
date: 2010-08-19 00:00:00 +10:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|