krammer 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/krammer +48 -20
  3. data/lib/krammer/version.rb +1 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2f0550d4951fe3c8ad720fbc7ad936705fc7e1dc
4
- data.tar.gz: 77a9523269c52bf5f79fb5dfa12628771eb04f71
3
+ metadata.gz: 8c5ca84aec32f339b226b1c914e94e2091b88913
4
+ data.tar.gz: bf815344ec9b210ea5bb62961c9161fa9c5e2baf
5
5
  SHA512:
6
- metadata.gz: 411ab0778ada659168fb29dd1b9e2e19bf9cb20d44ed11eef7c75615c63564d4a0b1d9cd6452c9c52624dcd45835e874b22425b824a28d282dca4d1b71e3ce65
7
- data.tar.gz: a8ae1b88d13397dddced8af3ab213129cabf72da17db0f72c2e585cc7c03c37f524319f1fa12b28fa70699fcc99f9baad264c7c243c9ccf0435914e379878189
6
+ metadata.gz: 0b9797d63b18a066fd57cdc6c0b78625f7b60ba47d4b24b004e142fd09e3a14f446ae07223fe3c8aac22361d0a346584fe9472904696aac68024a33b2173fab4
7
+ data.tar.gz: ef230c59c041bbf69d04efef0df7a237262d56589d2b8f404d877068af4db19f6b3cb79e075c9d1507658093f246c42f64286c67056904de2553ca574459f371
data/bin/krammer CHANGED
@@ -1,5 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ require "optparse"
3
4
  require "pathname"
4
5
  require "yaml"
5
6
  require "date"
@@ -18,32 +19,58 @@ class Info
18
19
  end
19
20
  end
20
21
 
21
- path = ""
22
- directory = ""
22
+ options = {}
23
23
 
24
- if ARGV.length == 0
25
- unless result = Dir.glob("*.markdown")[0]
26
- puts "\n\"*.markdown\" file not found in working directory..."
27
- exit 1
28
- else
29
- path = Pathname.new(result)
24
+ optparse = OptionParser.new do|opts|
25
+ opts.banner = "Usage: krammer [options] ..."
26
+
27
+ opts.on("-t", "--template TEMPLATE", "Use TEMPLATE as the template") do |t|
28
+ options[:template] = t
30
29
  end
31
- elsif ARGV.length == 1
32
-
33
- if (path = Pathname.new(ARGV[0])).relative?
34
- path = Pathname.new(Dir.pwd + "/" + ARGV[0])
30
+
31
+ opts.on("-i", "--input INPUT", "Use INPUT as the input file") do |i|
32
+ options[:input] = i
35
33
  end
36
34
 
37
- unless path.exist?
38
- puts "\nInvalid path..."
39
- exit 1
35
+ opts.on("-o", "--output OUTPUT", "Use OUTPUT as the basename") do |o|
36
+ options[:output] = o
40
37
  end
41
38
 
42
- else
43
- puts "\nToo many parameters..."
39
+ opts.on("-h", "--help", "Display the help screen" ) do
40
+ puts opts
41
+ exit 1
42
+ end
43
+ end
44
+
45
+ optparse.parse!
46
+
47
+ path = ""
48
+ directory = ""
49
+
50
+ unless input = options[:input]
51
+ unless input = Dir.glob("*.markdown")[0]
52
+ puts "\nInput file not found..."
53
+ exit 1
54
+ end
55
+ end
56
+
57
+ if (path = Pathname.new(input)).relative?
58
+ path = Pathname.new(Dir.pwd + "/" + input)
59
+ end
60
+
61
+ unless path.exist?
62
+ puts "\nInvalid path..."
44
63
  exit 1
45
64
  end
46
65
 
66
+ unless output = options[:output]
67
+ output = "output"
68
+ end
69
+
70
+ unless template = options[:template]
71
+ template = `echo $KRAMMER_TEMPLATE`.strip
72
+ end
73
+
47
74
  Dir.chdir(path.parent)
48
75
 
49
76
  fm = /^-{3}\n(.*\n)*?-{3}\n+/
@@ -82,10 +109,11 @@ while true
82
109
  content = source.sub(fm, "")
83
110
  body = Kramdown::Document.new(content, :auto_ids => false).to_latex
84
111
 
85
- output = ERB.new(File.read(`echo $KRAMMER_TEMPLATE`.strip)).result(Info.new(title: title, author: author, date: date, body: body).get_binding)
86
- open("output.tex", "w").write(output)
112
+ render = ERB.new(File.read(template)).result(Info.new(title: title, author: author, date: date, body: body).get_binding)
113
+
114
+ open("#{output}.tex", "w").write(render)
87
115
 
88
- puts `pdflatex -halt-on-error output.tex`
116
+ puts `pdflatex -halt-on-error #{output}.tex`
89
117
  puts "\nLast Update: #{DateTime.now.strftime("%Y-%m-%d %H:%M:%S.%L")}"
90
118
 
91
119
  time = File.mtime(path)
@@ -1,3 +1,3 @@
1
1
  module Krammer
2
- VERSION = "1.0.2"
2
+ VERSION = "1.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: krammer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kento Kaneko
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-06 00:00:00.000000000 Z
11
+ date: 2015-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler