krammer 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5b4313f93a2e7ee0b986e6877f2fd66b3020b076
4
- data.tar.gz: e788abef49cd0b2961b568bca1584c51bbcdbaa1
3
+ metadata.gz: 53ffaae311d547c1002ef5eeda97a292d7693b0b
4
+ data.tar.gz: 4ceb6d9d44b1e6e96e6a6362e5a114fa5ff94c64
5
5
  SHA512:
6
- metadata.gz: fa58ba08c6de6dffd8c233884e1272d8264af706a83ec5a8f4afc4b96f610129596a89852a882b73b8bac0380ed80b61585d9c0b11b393012797d5e4e13612a6
7
- data.tar.gz: 5e537a33b6953aef9cf19aa9c0425b10daee57714414b3816d093f0761bdf2513d1a4dae6a734f1205be3726e85182e4842ad2b0f13334958df38ffabb7e0934
6
+ metadata.gz: caa214ac4cd209c7fcae35a4d7a7e250cbb2b75e8d085c3ca4e324693cc41d669a8d6a6f8638849bbe82084c4dcbd6682675f98cdd74ee2773e8f7efad671415
7
+ data.tar.gz: ff91697999dac932d32971b17ca29cf5094857b0d3333f3492216ab5d8af70222970105c78e14b7eafb4f67d45f467f9b8aaa785b7e36cf48595df18fda96d18
data/.gitignore CHANGED
@@ -12,4 +12,5 @@
12
12
  *.so
13
13
  *.o
14
14
  *.a
15
- mkmf.log
15
+ mkmf.log
16
+ *.bbprojectd
@@ -1,81 +1,74 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "optparse"
4
- require "pathname"
5
- require "yaml"
6
- require "date"
7
- require "kramdown"
8
- require "erb"
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
- def initialize(hash)
13
- hash.each do |key, value|
14
- singleton_class.send(:define_method, key) { value }
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
- def get_binding()
19
- binding
20
- end
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
- opts.banner = "Usage: krammer [options] ..."
27
-
28
- opts.on("-i", "--input INPUT", "Use INPUT as the input file") do |i|
29
- options[:input] = i
30
- end
31
-
32
- opts.on("-o", "--output OUTPUT", "Use OUTPUT as the basename") do |o|
33
- options[:output] = o
34
- end
35
-
36
- opts.on("-t", "--template TEMPLATE", "Use TEMPLATE as the template") do |t|
37
- options[:template] = t
38
- end
39
-
40
- opts.on("-h", "--help", "Display the help screen" ) do
41
- puts opts
42
- exit 1
43
- end
44
-
45
- opts.on("-v", "--version", "Display the version number") do
46
- puts Krammer::VERSION
47
- exit 1
48
- end
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
- unless input = Dir.glob("*.markdown")[0]
58
- puts "\nInput file not found..."
59
- exit 1
60
- end
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
- path = Pathname.new(Dir.pwd + "/" + input)
62
+ path = Pathname.new(Dir.pwd + '/' + input)
65
63
  end
66
64
 
67
65
  unless path.exist?
68
- puts "\nInvalid path..."
69
- exit 1
66
+ puts "\nInvalid path..."
67
+ exit 1
70
68
  end
71
69
 
72
- unless output = options[:output]
73
- output = "output"
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
- while true
79
+ loop do
80
+ if time == File.mtime(path)
81
+ sleep(0.1)
82
+ next
83
+ end
87
84
 
88
- if time == File.mtime(path)
89
- sleep(0.1)
90
- next
91
- end
92
-
93
- unless source = open(path, "r").read
94
- source = ""
95
- end
96
-
97
- unless yml = source[fm]
98
- puts "\nInvalid YAML front matter\nRe-processing in 5 seconds..."
99
- sleep(5.0)
100
- next
101
- end
102
-
103
- unless meta = YAML.load(yml)
104
- meta = Hash.new
105
- end
106
-
107
- title = meta.has_key?("title") ? meta["title"] : "[Title]"
108
-
109
- author = meta.has_key?("author") ? meta["author"] : `echo $KRAMMER_AUTHOR`.strip
110
- author.sub!(/^$/, "[Author]")
111
-
112
- date = meta.has_key?("date") ? meta["date"] : DateTime.now
113
- date = date.strftime("%-d %B %Y")
114
-
115
- content = source.sub(fm, "")
116
- body = Kramdown::Document.new(content, :auto_ids => false).to_latex
117
-
118
- render = ERB.new(File.read(template)).result(Info.new(title: title, author: author, date: date, body: body).get_binding)
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
@@ -1,3 +1,3 @@
1
1
  module Krammer
2
- VERSION = "1.1.1"
2
+ VERSION = "1.1.2"
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.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-07 00:00:00.000000000 Z
11
+ date: 2015-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler