themedoc 0.1 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,28 @@
1
1
  % themedoc
2
2
  % theming pandoc
3
3
 
4
+ # Bugs and problems
5
+
6
+ ## Open
7
+
8
+ * Should see why it doesn't run rb 1.8
9
+ * Needs mostly testing
10
+ * Perhaps we need to push some stuff to separate files
11
+ * propagate exit code
12
+ - don't forget cleanup
13
+ - propagate pandocs stderr
14
+ * implement version
15
+
16
+ ## Closed
17
+
18
+ * no theme given use default html
19
+ * Should deal with missing extension and assume markdown input
20
+ * Default theme should use pdflate
21
+ * Message that states output file
22
+ * list of themes
23
+ * Snippets for before and after body
24
+
25
+
4
26
  # Features
5
27
 
6
28
  * Support different themes for pandoc
@@ -13,6 +35,12 @@
13
35
 
14
36
  # Getting started
15
37
 
38
+ ## Installation
39
+
40
+ gem install themedoc
41
+
42
+ ## Usage
43
+
16
44
  To `use themedoc's` default theme use the following incantation to
17
45
  create a pdf:
18
46
 
@@ -90,8 +90,21 @@ class Theme
90
90
  end
91
91
 
92
92
 
93
- def header
94
- @map['header']
93
+ def include(region_name)
94
+ unless @map['include']
95
+ return nil
96
+ end
97
+ @map['include'][region_name]
98
+
99
+ end
100
+
101
+
102
+ def before_body
103
+ @map['before-body']
104
+ end
105
+
106
+ def after_body
107
+ @map['after-body']
95
108
  end
96
109
 
97
110
  def parameters
@@ -104,9 +117,30 @@ class Theme
104
117
 
105
118
  end
106
119
 
120
+
121
+
107
122
  class CommandLineParser
108
123
  attr_reader :opts, :theme, :theme_path, :input_file_name
109
124
 
125
+ def initialize
126
+ home = `(cd; pwd)`
127
+ @theme_base_path = home.strip+"/.themedoc"
128
+ end
129
+
130
+ def load_theme(name)
131
+ @theme_path = @theme_base_path + "/" + name
132
+ @theme = Theme.new(YAML.load_file(theme_path + "/theme.yml"))
133
+ return @theme
134
+ end
135
+
136
+ def list_themes
137
+ puts "Available themes"
138
+ puts "----------------"
139
+ theme_names = `(cd #{@theme_base_path}; ls)`.split(/\n/)
140
+ theme_descriptions = theme_names.map{|n| load_theme(n)}
141
+ puts theme_names.zip(theme_descriptions).map{|t| t[0] + " => " + t[1].to_s}.join("\n")
142
+ end
143
+
110
144
  def parse()
111
145
  theme_index=ARGV.index("--theme") || ARGV.index("-t");
112
146
 
@@ -115,15 +149,21 @@ class CommandLineParser
115
149
  throw "No theme value provided"
116
150
  end
117
151
  theme_name = ARGV[theme_index + 1 ]
118
- home = `(cd; pwd)`
119
- @theme_path = home.strip+"/.themedoc/#{theme_name}"
120
- @theme = Theme.new(YAML.load_file(theme_path + "/theme.yml"))
152
+ load_theme(theme_name)
153
+ end
154
+
155
+ default_theme = false;
156
+ if (!@theme)
157
+ load_theme("default-html")
158
+ default_theme = true;
121
159
  end
122
160
 
123
161
  theme = @theme
124
162
 
163
+
125
164
  @opts = Trollop::options do
126
165
  opt :theme, "Theme to be used", :type => String, :short => 't'
166
+ opt :list_themes, "List available themes"
127
167
  opt :debug, "Do not remove temp files"
128
168
  if (theme)
129
169
  theme.parameters.each{|param|
@@ -132,12 +172,20 @@ class CommandLineParser
132
172
  end
133
173
  end
134
174
 
135
- Trollop::die :theme, "theme must be specified" if !@opts[:theme]
175
+ if (@opts[:list_themes])
176
+ list_themes
177
+ exit
178
+ end
179
+
180
+ if (default_theme)
181
+ puts "No theme provided - using default-html"
182
+ end
136
183
 
137
184
  if (ARGV.length == 0)
138
185
  throw "No input file specified"
139
186
  end
140
187
 
188
+
141
189
  @input_file_name = ARGV[0]
142
190
  end
143
191
  end
@@ -164,8 +212,14 @@ parser.parse()
164
212
 
165
213
  theme = parser.theme
166
214
 
167
- output_file_name = parser.input_file_name().gsub(/.md$/, "." +theme.target_extension)
168
- header_snippet_name = "." + parser.input_file_name() + ".header"
215
+ if (/\.[^.]*$/ =~ parser.input_file_name())
216
+ output_file_name = parser.input_file_name().gsub(/\.[^.]*$/, "." +theme.target_extension)
217
+ else
218
+ output_file_name = parser.input_file_name() + "." + theme.target_extension
219
+ end
220
+
221
+ puts "Writing output to #{output_file_name}"
222
+
169
223
 
170
224
  pandoc_opts = theme.pandoc_opts
171
225
  pandoc_vars = theme.pandoc_vars
@@ -179,16 +233,22 @@ pandoc_opts["output"] = output_file_name
179
233
  `ln -fs #{parser.theme_path}/resources .resources`
180
234
 
181
235
  template_parameters = {}
182
- theme.template_parameters
183
- .map{|param| param['name']}
236
+ theme.template_parameters \
237
+ .map{|param| param['name']} \
184
238
  .each{|p_name| template_parameters[p_name]=parser.opts[p_name.to_sym]}
185
239
 
240
+ regions = ["in-header", "before-body", "after-body"]
241
+
242
+ regions.each{|region_name|
243
+ snippet_file_name= "." + parser.input_file_name() + "." + region_name
244
+ if (theme.include(region_name))
245
+ region_content = Mustache.render(theme.include(region_name), template_parameters);
246
+ File.open(snippet_file_name, "w+") { |f| f << region_content}
247
+ pandoc_opts['include-' + region_name]=snippet_file_name
248
+ end
249
+ }
250
+
186
251
 
187
- if (theme.header)
188
- header = Mustache.render(theme.header, template_parameters);
189
- File.open(header_snippet_name, "w+") { |f| f << header}
190
- pandoc_opts['include-in-header']=header_snippet_name
191
- end
192
252
 
193
253
  pandoc=Pandoc.new(pandoc_opts, pandoc_vars, parser.input_file_name)
194
254
  pandoc.run
@@ -199,6 +259,8 @@ if (parser.opts[:debug])
199
259
  end
200
260
 
201
261
  `rm .resources`
202
- `rm -f #{header_snippet_name}`
203
-
262
+ regions.each{|region_name|
263
+ snippet_file_name= "." + parser.input_file_name() + "." + region_name
264
+ `rm -f #{snippet_file_name}`
265
+ }
204
266
 
@@ -3,7 +3,7 @@ Gem::Specification.new do |s|
3
3
  s.summary = 'themedoc is a theming frontend for pandoc'
4
4
  s.description = 'themedoc is a theming frontend for pandoc that allows grouping
5
5
  parameters, extra resources and output snippets into named themes'
6
- s.version = '0.1'
6
+ s.version = '0.2'
7
7
  s.platform = Gem::Platform::RUBY
8
8
 
9
9
  s.files = ['bin/themedoc']
@@ -1,4 +1,4 @@
1
- description: Template for formal TWDE reports
1
+ description: Template for html reports
2
2
 
3
3
  target-extension: html
4
4
 
@@ -0,0 +1,54 @@
1
+ description: Template for pdf reports using xelatex
2
+
3
+ target-extension: pdf
4
+
5
+ pandoc-opts:
6
+ toc: true
7
+ standalone: true
8
+ self-contained: true
9
+ latex-engine: xelatex
10
+ number-sections: true
11
+
12
+ pandoc-vars:
13
+ lang: english
14
+ graphics: true
15
+ documentclass: scrartcl
16
+
17
+ parameters:
18
+ - name: title-header
19
+ type: string
20
+ target: template
21
+ desc: Header for the title page
22
+
23
+ - name: "no-toc"
24
+ type: bool
25
+ target: option-override
26
+ desc: suppress table of contents
27
+ original-name: toc
28
+ inverted: true
29
+
30
+ - name: lang
31
+ type: string
32
+ desc: language of the document, e.g. english or german
33
+ target: variable-override
34
+
35
+
36
+ include:
37
+ in-header: |
38
+ {{=<% %>=}}
39
+ \usepackage{xltxtra,fontspec,xunicode}
40
+ \titlehead{<%title-header%>}
41
+ \setmainfont{Garamond}
42
+ %\setromanfont[Numbers=Uppercase]{Georgia}
43
+ \KOMAoptions{titlepage=true,abstract=false}
44
+ \publishers{
45
+ \Oldincludegraphics[height=18ex]{.resources/logo.png}
46
+ \vspace{3ex}
47
+ }
48
+
49
+ before-body: |
50
+ Here the body doth start.
51
+
52
+ after-body: |
53
+ The body ends here.
54
+
@@ -1,4 +1,4 @@
1
- description: Template for formal TWDE reports
1
+ description: Default template for pdf with table of contents and numbered sections
2
2
 
3
3
  target-extension: pdf
4
4
 
@@ -6,13 +6,13 @@ pandoc-opts:
6
6
  toc: true
7
7
  standalone: true
8
8
  self-contained: true
9
- latex-engine: xelatex
9
+ latex-engine: pdflatex
10
10
  number-sections: true
11
11
 
12
12
  pandoc-vars:
13
13
  lang: english
14
- graphics: true
15
- documentclass: scrartcl
14
+ #graphics: true
15
+ documentclass: article
16
16
 
17
17
  parameters:
18
18
  - name: title-header
@@ -33,15 +33,7 @@ parameters:
33
33
  target: variable-override
34
34
 
35
35
 
36
- header: |
37
- {{=<% %>=}}
38
- \usepackage{xltxtra,fontspec,xunicode}
39
- \titlehead{<%title-header%>}
40
- \setmainfont{Garamond}
41
- %\setromanfont[Numbers=Uppercase]{Georgia}
42
- \KOMAoptions{titlepage=true,abstract=false}
43
- \publishers{
44
- \Oldincludegraphics[height=18ex]{.resources/logo.png}
45
- \vspace{3ex}
46
- }
36
+ include:
37
+ in-header: |
38
+ {{=<% %>=}}
47
39
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: themedoc
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: '0.2'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-24 00:00:00.000000000Z
12
+ date: 2012-08-01 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: trollop
16
- requirement: &2152721800 !ruby/object:Gem::Requirement
16
+ requirement: &2157178460 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2152721800
24
+ version_requirements: *2157178460
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: mustache
27
- requirement: &2152721360 !ruby/object:Gem::Requirement
27
+ requirement: &2157178020 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2152721360
35
+ version_requirements: *2157178020
36
36
  description: ! "themedoc is a theming frontend for pandoc that allows grouping\n parameters,
37
37
  extra resources and output snippets into named themes"
38
38
  email: ''
@@ -48,6 +48,8 @@ files:
48
48
  - themedoc.gemspec
49
49
  - themes/default-html/resources/default.css
50
50
  - themes/default-html/theme.yml
51
+ - themes/default-xelatex/resources/logo.png
52
+ - themes/default-xelatex/theme.yml
51
53
  - themes/default/resources/logo.png
52
54
  - themes/default/theme.yml
53
55
  homepage: https://github.com/fleipold/themedoc