krammer 1.1.1 → 1.1.2
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.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/bin/krammer +82 -93
- data/lib/krammer/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 53ffaae311d547c1002ef5eeda97a292d7693b0b
|
4
|
+
data.tar.gz: 4ceb6d9d44b1e6e96e6a6362e5a114fa5ff94c64
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: caa214ac4cd209c7fcae35a4d7a7e250cbb2b75e8d085c3ca4e324693cc41d669a8d6a6f8638849bbe82084c4dcbd6682675f98cdd74ee2773e8f7efad671415
|
7
|
+
data.tar.gz: ff91697999dac932d32971b17ca29cf5094857b0d3333f3492216ab5d8af70222970105c78e14b7eafb4f67d45f467f9b8aaa785b7e36cf48595df18fda96d18
|
data/.gitignore
CHANGED
data/bin/krammer
CHANGED
@@ -1,81 +1,74 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
3
|
+
require 'optparse'
|
4
|
+
require 'pathname'
|
5
|
+
require 'yaml'
|
6
|
+
require 'date'
|
7
|
+
require 'kramdown'
|
8
|
+
require 'erb'
|
9
9
|
require 'krammer/version'
|
10
10
|
|
11
|
+
# Info class that holds meta-info about the document
|
11
12
|
class Info
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
end
|
13
|
+
def initialize(hash)
|
14
|
+
hash.each do |key, value|
|
15
|
+
singleton_class.send(:define_method, key) { value }
|
16
16
|
end
|
17
|
+
end
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
19
|
+
def get_binding
|
20
|
+
binding
|
21
|
+
end
|
21
22
|
end
|
22
23
|
|
23
24
|
options = {}
|
24
25
|
|
25
26
|
optparse = OptionParser.new do|opts|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
27
|
+
opts.banner = 'Usage: krammer [options] ...'
|
28
|
+
|
29
|
+
opts.on('-i', '--input INPUT', 'Use INPUT as the input file') do |i|
|
30
|
+
options[:input] = i
|
31
|
+
end
|
32
|
+
|
33
|
+
opts.on('-o', '--output OUTPUT', 'Use OUTPUT as the basename') do |o|
|
34
|
+
options[:output] = o
|
35
|
+
end
|
36
|
+
|
37
|
+
opts.on('-t', '--template TEMPLATE', 'Use TEMPLATE as the template') do |t|
|
38
|
+
options[:template] = t
|
39
|
+
end
|
40
|
+
|
41
|
+
opts.on('-h', '--help', 'Display the help screen') do
|
42
|
+
puts opts
|
43
|
+
exit 1
|
44
|
+
end
|
45
|
+
|
46
|
+
opts.on('-v', '--version', 'Display the version number') do
|
47
|
+
puts Krammer::VERSION
|
48
|
+
exit 1
|
49
|
+
end
|
49
50
|
end
|
50
51
|
|
51
52
|
optparse.parse!
|
52
53
|
|
53
|
-
path = ""
|
54
|
-
directory = ""
|
55
|
-
|
56
54
|
unless input = options[:input]
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
55
|
+
unless input = Dir.glob('*.markdown')[0]
|
56
|
+
puts "\nInput file not found..."
|
57
|
+
exit 1
|
58
|
+
end
|
61
59
|
end
|
62
60
|
|
63
61
|
if (path = Pathname.new(input)).relative?
|
64
|
-
|
62
|
+
path = Pathname.new(Dir.pwd + '/' + input)
|
65
63
|
end
|
66
64
|
|
67
65
|
unless path.exist?
|
68
|
-
|
69
|
-
|
66
|
+
puts "\nInvalid path..."
|
67
|
+
exit 1
|
70
68
|
end
|
71
69
|
|
72
|
-
unless output = options[:output]
|
73
|
-
|
74
|
-
end
|
75
|
-
|
76
|
-
unless template = options[:template]
|
77
|
-
template = `echo $KRAMMER_TEMPLATE`.strip
|
78
|
-
end
|
70
|
+
output = 'output' unless (output = options[:output])
|
71
|
+
template = `echo $KRAMMER_TEMPLATE`.strip unless (template = options[:template])
|
79
72
|
|
80
73
|
Dir.chdir(path.parent)
|
81
74
|
|
@@ -83,44 +76,40 @@ fm = /^-{3}\n(.*\n)*?-{3}\n+/
|
|
83
76
|
|
84
77
|
time = NIL
|
85
78
|
|
86
|
-
|
79
|
+
loop do
|
80
|
+
if time == File.mtime(path)
|
81
|
+
sleep(0.1)
|
82
|
+
next
|
83
|
+
end
|
87
84
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
open("#{output}.tex", "w").write(render)
|
121
|
-
|
122
|
-
puts `pdflatex -halt-on-error #{output}.tex`
|
123
|
-
puts "\nLast Update: #{DateTime.now.strftime("%Y-%m-%d %H:%M:%S.%L")}"
|
124
|
-
|
125
|
-
time = File.mtime(path)
|
126
|
-
end
|
85
|
+
source = '' unless (source = open(path, 'r').read)
|
86
|
+
|
87
|
+
unless yml = source[fm]
|
88
|
+
puts "\nInvalid YAML front matter\nRe-processing in 5 seconds..."
|
89
|
+
sleep(5.0)
|
90
|
+
next
|
91
|
+
end
|
92
|
+
|
93
|
+
meta = {} unless (meta = YAML.load(yml))
|
94
|
+
|
95
|
+
title = meta.key?('title') ? meta['title'] : '[Title]'
|
96
|
+
|
97
|
+
author = meta.key?('author') ? meta['author'] : `echo $KRAMMER_AUTHOR`.strip
|
98
|
+
author.sub!(/^$/, '[Author]')
|
99
|
+
|
100
|
+
date = meta.key?('date') ? meta['date'] : DateTime.now
|
101
|
+
date = date.strftime('%-d %B %Y')
|
102
|
+
|
103
|
+
content = source.sub(fm, '')
|
104
|
+
body = Kramdown::Document.new(content, auto_ids: false).to_latex
|
105
|
+
|
106
|
+
info = Info.new(title: title, author: author, date: date, body: body)
|
107
|
+
render = ERB.new(File.read(template)).result(info.get_binding)
|
108
|
+
|
109
|
+
open("#{output}.tex", 'w').write(render)
|
110
|
+
|
111
|
+
puts `pdflatex -halt-on-error #{output}.tex`
|
112
|
+
puts "\nLast Update: #{DateTime.now.strftime('%Y-%m-%d %H:%M:%S.%L')}"
|
113
|
+
|
114
|
+
time = File.mtime(path)
|
115
|
+
end
|
data/lib/krammer/version.rb
CHANGED
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.1.
|
4
|
+
version: 1.1.2
|
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-
|
11
|
+
date: 2015-01-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|