hyla 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +8 -8
  2. data/README.adoc +38 -3
  3. data/bin/hyla +21 -8
  4. data/data/toc.adoc +3 -3
  5. data/documentation/introduction.adoc +30 -26
  6. data/documentation/scripts/create_adoc_from_toc.sh +3 -0
  7. data/documentation/scripts/create_myblankproject_add_artefacts.sh +7 -7
  8. data/documentation/scripts/create_myblankproject_add_artefacts_config.sh +14 -8
  9. data/documentation/scripts/create_myblankproject_add_artefacts_my_config.sh +15 -0
  10. data/documentation/scripts/generate_content_myblankproject.sh +7 -7
  11. data/documentation/scripts/generate_content_myblankproject_config.sh +17 -11
  12. data/documentation/scripts/generate_content_myblankproject_other_style.sh +7 -7
  13. data/documentation/scripts/generate_pdf_from_html.sh +1 -1
  14. data/documentation/scripts/generate_slideshow_deckjs.sh +4 -4
  15. data/documentation/scripts/generate_slideshow_mytoc_all.sh +2 -2
  16. data/documentation/scripts/generate_slideshow_mytoc_module.sh +1 -1
  17. data/documentation/scripts/generate_slideshow_revealjs.sh +13 -4
  18. data/documentation/scripts/generate_slideshow_revealjs_config.sh +36 -0
  19. data/documentation/scripts/sendmail.sh +1 -1
  20. data/hyla.gemspec +2 -1
  21. data/lib/hyla.rb +2 -1
  22. data/lib/hyla/commands/{create.rb → add.rb} +18 -1
  23. data/lib/hyla/commands/generate.rb +215 -44
  24. data/lib/hyla/commands/new.rb +16 -9
  25. data/lib/hyla/commands/sendmail.rb +37 -13
  26. data/lib/hyla/commands/serve.rb +2 -2
  27. data/lib/hyla/configuration.rb +73 -33
  28. data/lib/hyla/core_ext.rb +11 -1
  29. data/lib/hyla/project.rb +1 -1
  30. data/lib/resources/backends/haml/revealjs/document.html.haml +9 -2
  31. data/lib/resources/backends/slim/html5/block_image.html.slim +1 -0
  32. data/lib/resources/backends/slim/html5/document.html.slim +18 -9
  33. data/lib/resources/backends/slim/revealjs/block_sidebar.html.slim +5 -5
  34. data/lib/resources/backends/slim/revealjs/document.html.slim +10 -2
  35. data/lib/resources/backends/slim/revealjs/section.html.slim +5 -1
  36. data/lib/resources/cover.slim +70 -0
  37. data/lib/resources/fonts/liberation/Sans-Bold.ttf +0 -0
  38. data/lib/resources/fonts/liberation/Sans-BoldItalic.ttf +0 -0
  39. data/lib/resources/fonts/liberation/Sans-Italic.ttf +0 -0
  40. data/lib/resources/fonts/liberation/Sans-Regular.ttf +0 -0
  41. data/lib/resources/revealjs/css/theme/gpe.css +225 -0
  42. data/lib/resources/styles/liberation.css +3 -1
  43. data/lib/templates/_config.yaml +26 -8
  44. data/lib/templates/book/readme.adoc +1 -1
  45. data/lib/templates/sample/{asciidoc_article.adoc → asciidoc_article.ad} +0 -0
  46. data/lib/templates/sample/{asciidoc_audio.adoc → asciidoc_audio.ad} +0 -0
  47. data/lib/templates/sample/{asciidoc_book.adoc → asciidoc_book.ad} +0 -0
  48. data/lib/templates/sample/{asciidoc_image.adoc → asciidoc_image.ad} +0 -0
  49. data/lib/templates/sample/{asciidoc_report.adoc → asciidoc_report.ad} +3 -2
  50. data/lib/templates/sample/{asciidoc_source.adoc → asciidoc_source.ad} +0 -0
  51. data/lib/templates/sample/{asciidoc_table.adoc → asciidoc_table.ad} +0 -0
  52. data/lib/templates/sample/{asciidoc_video.adoc → asciidoc_video.ad} +0 -0
  53. data/lib/templates/sample/{slideshow_deckjs.adoc → slideshow_deckjs.ad} +0 -0
  54. data/lib/templates/sample/{slideshow_revealjs.adoc → slideshow_revealjs.ad} +1 -1
  55. data/lib/templates/training-exercises/{README.md → README.ad} +0 -0
  56. data/lib/templates/training/readme.adoc +1 -1
  57. metadata +61 -32
  58. data/documentation/scripts/create_adoc_from_toc_config.sh +0 -24
  59. data/lib/resources/backends/slim/document.html.bk.slim +0 -335
  60. data/lib/resources/styles/redhat.css +0 -1
  61. data/test/reports/test-1.0.x-11-12-2013.txt +0 -123
@@ -10,13 +10,13 @@ cd ~/hyla/MyBlankProject
10
10
 
11
11
  echo "Add asciidoc files"
12
12
  hyla new -b -d MyBlankProject --force
13
- hyla create --t asciidoc --a article --d ~/hyla/MyBlankProject
14
- hyla create --t asciidoc --a book --d ~/hyla/MyBlankProject
15
- hyla create --t asciidoc --a image --d ~/hyla/MyBlankProject
16
- hyla create --t asciidoc --a audio --d ~/hyla/MyBlankProject
17
- hyla create --t asciidoc --a video --d ~/hyla/MyBlankProject
18
- hyla create --t asciidoc --a source --d ~/hyla/MyBlankProject
19
- hyla create --t asciidoc --a table --d ~/hyla/MyBlankProject
13
+ hyla add --t asciidoc --a article --d ~/hyla/MyBlankProject
14
+ hyla add --t asciidoc --a book --d ~/hyla/MyBlankProject
15
+ hyla add --t asciidoc --a image --d ~/hyla/MyBlankProject
16
+ hyla add --t asciidoc --a audio --d ~/hyla/MyBlankProject
17
+ hyla add --t asciidoc --a video --d ~/hyla/MyBlankProject
18
+ hyla add --t asciidoc --a source --d ~/hyla/MyBlankProject
19
+ hyla add --t asciidoc --a table --d ~/hyla/MyBlankProject
20
20
 
21
21
  echo "Change style in the _config.yaml file"
22
22
  ruby -i.bak -pe 'sub(%r{style: liberation},"style: foundation")' _config.yaml
@@ -9,7 +9,7 @@ cd MyPdfProject
9
9
 
10
10
  echo "Create one Asciidoc file from sample (book)"
11
11
 
12
- hyla create -a book --t asciidoc -d .
12
+ hyla add -a book --t asciidoc -d .
13
13
 
14
14
  echo "Generate HTML content using foundation stylesheet"
15
15
 
@@ -8,11 +8,11 @@ echo "Create a blank project"
8
8
  hyla new -b -d MyDeckSlideShow
9
9
 
10
10
  echo "Create from slideshow template a DeckJS file"
11
- hyla create --t slideshow -a deckjs -d MyDeckSlideShow
11
+ hyla add --t slideshow -a deckjs -d MyDeckSlideShow
12
12
 
13
13
  echo "Generate HTML5 Slideshow content"
14
- hyla generate --backend deckjs -s ~/hyla/MyDeckSlideShow -d ~/hyla/MyDeckSlideShow/generated_content -r adoc2htmlslide -a deckjs_theme=swiss,deckjs_transition=fade
14
+ hyla generate --backend deckjs -s ~/hyla/MyDeckSlideShow -d ~/hyla/MyDeckSlideShow/generated_content -r adoc2html -a deckjs_theme=swiss,deckjs_transition=fade
15
15
 
16
- # hyla generate --backend deckjs -s ~/hyla/MyDeckSlideShow -d ~/hyla/MyDeckSlideShow/generated_content -r adoc2htmlslide
17
- # hyla generate --backend deckjs -s ~/hyla/MyDeckSlideShow -d ~/hyla/MyDeckSlideShow/generated_content -r adoc2htmlslide -a deckjs_theme=web-2.0,deckjs_transition=horizontal-slide
16
+ # hyla generate --backend deckjs -s ~/hyla/MyDeckSlideShow -d ~/hyla/MyDeckSlideShow/generated_content -r adoc2html
17
+ # hyla generate --backend deckjs -s ~/hyla/MyDeckSlideShow -d ~/hyla/MyDeckSlideShow/generated_content -r adoc2html -a deckjs_theme=web-2.0,deckjs_transition=horizontal-slide
18
18
 
@@ -8,10 +8,10 @@ source create_adoc_from_toc.sh $1 $2
8
8
  cd ~/hyla/MyTocProject
9
9
 
10
10
  # echo "Generate slideshow for a module using deckjs as backend"
11
- hyla generate --backend deckjs -s . -d generated_content_deckjs -r index2htmlslide
11
+ hyla generate --backend deckjs -s . -d generated_content_deckjs -r index2html
12
12
  open ~/hyla/MyTocProject/generated_content_deckjs/my-project_AllSlides.html
13
13
 
14
14
  # echo "Generate slideshow for a module using revealjs as backend"
15
- hyla generate --backend revealjs -s . -d generated_content_reveal -r index2htmlslide
15
+ hyla generate --backend revealjs -s . -d generated_content_reveal -r index2html
16
16
 
17
17
  open ~/hyla/MyTocProject/generated_content_reveal/my-project_AllSlides.html
@@ -7,4 +7,4 @@ source create_adoc_from_toc.sh $1 $2
7
7
 
8
8
  echo "Generate slideshow for a module using deckjs as backend"
9
9
  cd ~/hyla/MyTocProject
10
- hyla generate --backend deckjs -s A_Introduction_module/ -d A_Introduction_module/generated_content -r index2htmlslide
10
+ hyla generate --backend deckjs -s A_Introduction_module/ -d A_Introduction_module/generated_content -r index2html
@@ -8,16 +8,25 @@ echo "Create a blank project"
8
8
  hyla new --blank -d MyRevealSlideShow
9
9
 
10
10
  echo "Create from slideshow template a RevealJS file"
11
- hyla create --t slideshow -a revealjs -d MyRevealSlideShow
11
+ hyla add --t slideshow -a revealjs -d MyRevealSlideShow
12
12
 
13
13
  echo "Generate HTML5 Slideshow content"
14
14
  cd MyRevealSlideShow
15
15
 
16
- hyla generate --backend revealjs -s . -d generated_content -r adoc2htmlslide
16
+ echo "Copy logo"
17
+ cp -r /Users/chmoulli/hyla/RevealCreatedContent/image ./image
18
+
19
+ echo "Change theme to GPE"
20
+ ruby -i.bak -pe 'sub(%r{revealjs_theme: deault},"revealjs_theme: gpe")' _config.yaml
21
+
22
+ hyla generate --backend revealjs -s . -d generated_content -r adoc2html --trace
17
23
 
18
24
  echo "Open the slideshow using your web browser"
19
- open http://localhost:4000/hyla/slideshow_revealjs.html &
25
+ # open http://localhost:4000/hyla/slideshow_revealjs.html &
20
26
 
21
27
  echo "Start web server"
22
- hyla serve -P 4000 -H localhost -b /hyla/ -d generated_content/
28
+ # hyla serve -P 4000 -H localhost -b /hyla/ -d generated_content/
29
+
30
+ echo "Change theme to GPE"
31
+ ruby -i.bak -pe 'sub(%r{revealjs_theme: gpe},"revealjs_theme: default")' _config.yaml
23
32
 
@@ -0,0 +1,36 @@
1
+ #!/bin/sh
2
+
3
+ echo "Remove MyRevealJS"
4
+ rm -rf ~/hyla/MyRevealSlideShow
5
+ cd ~/hyla
6
+
7
+ echo "Create a blank project"
8
+ hyla new --blank -d MyRevealSlideShow
9
+
10
+ echo "Create from slideshow template a RevealJS file"
11
+ hyla add --t slideshow -a revealjs -d MyRevealSlideShow
12
+
13
+ echo "Generate HTML5 Slideshow content"
14
+ cd MyRevealSlideShow
15
+
16
+ echo "Change theme to GPE, backend to reveal"
17
+ ruby -i.bak -pe 'sub(%r{revealjs_theme: default},"revealjs_theme: gpe")' _config.yaml
18
+ ruby -i.bak -pe 'sub(%r{backend: html5},"backend: revealjs")' _config.yaml
19
+ ruby -i.bak -pe 'sub(%r{rendering: adoc2html},"rendering: adoc2html")' _config.yaml
20
+
21
+ hyla generate
22
+
23
+ echo "Copy logo"
24
+ cp -r /Users/chmoulli/hyla/RevealCreatedContent/image ./generated_content/image
25
+
26
+ echo "Open the slideshow using your web browser"
27
+ # open http://localhost:4000/hyla/slideshow_revealjs.html &
28
+
29
+ echo "Start web server"
30
+ # hyla serve -P 4000 -H localhost -b /hyla/ -d generated_content/
31
+
32
+ echo "Change theme to GPE"
33
+ #ruby -i.bak -pe 'sub(%r{revealjs_theme: gpe},"revealjs_theme: default")' _config.yaml
34
+ #ruby -i.bak -pe 'sub(%r{backend: revealjs},"backend: html5")' _config.yaml
35
+ #ruby -i.bak -pe 'sub(%r{rendering: adoc2html},"rendering: adoc2html")' _config.yaml
36
+
@@ -8,7 +8,7 @@ hyla new -b -d ~/hyla/MyEmailProject --force
8
8
  cd ~/hyla/MyEmailProject
9
9
 
10
10
  echo "Add an artefact - asciidoc with images"
11
- hyla create --a image --d ~/hyla/MyEmailProject
11
+ hyla add --a image --d ~/hyla/MyEmailProject
12
12
 
13
13
  echo "Generate HTML content"
14
14
  hyla generate -r adoc2html -s ~/hyla/MyEmailProject/ -d ~/hyla/MyEmailProject/generated_content
data/hyla.gemspec CHANGED
@@ -34,7 +34,8 @@ Gem::Specification.new do |s|
34
34
  s.add_runtime_dependency 'listen', '~> 1.3', '>= 1.3.1'
35
35
  s.add_runtime_dependency 'safe_yaml', '~> 1.0', '>= 1.0.0'
36
36
  s.add_runtime_dependency 'mail', '~> 2.5', '>= 2.5.4'
37
- s.add_runtime_dependency 'pdfkit', '~> 0.5', '>= 0.5.4'
37
+ s.add_runtime_dependency 'wkhtmltopdf-binary', '~> 0.1', '>= 0.1.2'
38
+ s.add_runtime_dependency 'imgkit', '~> 1.0', '>= 1.0.3'
38
39
 
39
40
  # Colorize Text Terminal
40
41
  s.add_runtime_dependency 'colorator', '~> 0.1'
data/lib/hyla.rb CHANGED
@@ -31,7 +31,8 @@ require 'webrick'
31
31
  require 'find'
32
32
  require 'mail'
33
33
  require 'mime/types'
34
- require 'pdfkit'
34
+ require 'slim'
35
+ require 'imgkit'
35
36
 
36
37
  # internal requires
37
38
  require 'hyla/logger'
@@ -1,11 +1,14 @@
1
1
  module Hyla
2
2
  module Commands
3
- class Create < Command
3
+ class Add < Command
4
4
 
5
5
  def self.process(args, options)
6
6
  destination = options[:destination] if check_mandatory_option?('-d / --destination', options[:destination])
7
7
  artefact_type = options[:artefact_type] if check_mandatory_option?('-a / --artefact_type', options[:artefact_type])
8
8
  type = options[:type] if check_mandatory_option?('-t / --type', options[:type])
9
+ font_type = 'liberation'
10
+
11
+ copy_fonts(font_type, destination)
9
12
 
10
13
  copy_artefact(type, artefact_type, destination)
11
14
  end
@@ -29,6 +32,20 @@ module Hyla
29
32
  end
30
33
  end
31
34
 
35
+ #
36
+ # Copy fonts
37
+ #
38
+ def self.copy_fonts(type, destination)
39
+ source = [Configuration::fonts, type] * '/'
40
+ destination = [destination, 'fonts'] * '/'
41
+ destination = File.expand_path destination
42
+
43
+ FileUtils.mkdir_p(destination) unless File.exists?(destination)
44
+ FileUtils.cp_r source, destination
45
+
46
+ Hyla::logger.info ">> Fonts #{type} added to project #{destination}"
47
+ end
48
+
32
49
  end # class Create
33
50
  end # module Commands
34
51
  end # module Hyla
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  module Hyla
2
3
  module Commands
3
4
  class Generate < Command
@@ -8,23 +9,16 @@ module Hyla
8
9
 
9
10
  case rendering
10
11
 
11
- when 'html2pdf'
12
-
13
- Hyla.logger.info "Rendering : Generate PDF from HTML file"
14
-
15
- source_dir = options[:source] if self.check_mandatory_option?('-s / --source', options[:source])
16
- out_dir = options[:destination] if self.check_mandatory_option?('-d / --destination', options[:destination])
17
- file_name = options[:file] if self.check_mandatory_option?('-f / --file', options[:file])
18
-
19
- self.html_to_pdf(source_dir, out_dir, file_name)
20
-
21
12
  when 'toc2adoc'
22
13
 
23
14
  Hyla.logger.info "Rendering : Table of Content to Asciidoc"
24
15
  self.check_mandatory_option?('-t / --toc', options[:toc])
16
+ self.check_mandatory_option?('-d / --destination', options[:destination])
17
+
25
18
  @toc_file = options[:toc]
26
19
  @out_dir = options[:destination]
27
- @project_name = options[:project_name]
20
+ @project_name = options[:project_name] if options[:project_name]
21
+ @project_name = 'My Project' if !options[:project_name]
28
22
 
29
23
  self.table_of_content_to_asciidoc(@toc_file, @out_dir, @project_name)
30
24
 
@@ -39,6 +33,7 @@ module Hyla
39
33
 
40
34
  # Check Style to be used
41
35
  new_asciidoctor_option = {
36
+ :template_dirs => [self.backend_dir(options[:backend])],
42
37
  :attributes => {
43
38
  'stylesheet' => self.check_style(options[:style])
44
39
  }
@@ -50,7 +45,7 @@ module Hyla
50
45
 
51
46
  self.asciidoc_to_html(@source, @destination, extensions, merged_options)
52
47
 
53
- when 'index2htmlslide'
48
+ when 'index2html'
54
49
  Hyla.logger.info "Rendering : Asciidoctor Indexed Files to SlideShow"
55
50
  self.check_mandatory_option?('-s / --source', options[:source])
56
51
  self.check_mandatory_option?('-d / --destination', options[:destination])
@@ -72,27 +67,57 @@ module Hyla
72
67
 
73
68
  self.asciidoc_to_html(@source, @destination, extensions, merged_options)
74
69
 
75
- when 'adoc2htmlslide'
76
- Hyla.logger.info "Rendering : Asciidoc to SlideShow"
77
- self.check_mandatory_option?('-s / --source', options[:source])
78
- self.check_mandatory_option?('-d / --destination', options[:destination])
70
+ when 'html2pdf'
79
71
 
80
- @destination = options[:destination]
81
- @source = options[:source]
72
+ Hyla.logger.info "Rendering : Generate PDF from HTML file"
82
73
 
83
- new_asciidoctor_option = {
84
- :template_dirs => [self.backend_dir(options[:backend])],
85
- :attributes => {
86
- 'stylesheet' => self.check_style(options[:style])
87
- }
88
- }
74
+ source_dir = options[:source] if self.check_mandatory_option?('-s / --source', options[:source])
75
+ out_dir = options[:destination] if self.check_mandatory_option?('-d / --destination', options[:destination])
89
76
 
90
- merged_options = Configuration[options].deep_merge(new_asciidoctor_option)
77
+ file_name = options[:file]
78
+ cover_path ||= options[:cover_path]
79
+ header_html_path = options[:header_html_path]
80
+ footer_text = options[:footer_text]
91
81
 
92
- # Extension(s) of the files to be parsed
93
- extensions = 'adoc|ad|asciidoc'
82
+ self.html_to_pdf(file_name, source_dir, out_dir, footer_text, header_html_path, cover_path)
83
+
84
+ when 'cover2png'
85
+
86
+ Hyla.logger.info "Rendering : Generate Cover HTML page & picture - format png"
87
+
88
+ out_dir = options[:destination] if self.check_mandatory_option?('-d / --destination', options[:destination])
89
+ file_name = options[:cover_file]
90
+ image_name = options[:cover_image]
91
+
92
+ # Configure Slim engine
93
+ slim_file = Configuration::cover_template
94
+ slim_tmpl = File.read(slim_file)
95
+ template = Slim::Template.new(:pretty => true) { slim_tmpl }
96
+
97
+ # Do the Rendering HTML
98
+ parameters = {:course_name => options[:course_name],
99
+ :module_name => options[:module_name],
100
+ :image_path => options[:image_path]}
101
+ res = template.render(Object.new, parameters)
102
+
103
+ unless Dir.exist? out_dir
104
+ FileUtils.mkdir_p out_dir
105
+ end
106
+
107
+ Dir.chdir(out_dir) do
108
+ out_file = File.new(file_name, 'w')
109
+ out_file.puts res
110
+ out_file.puts "\n"
111
+
112
+ # Do the Rendering Image
113
+ kit = IMGKit.new(res, quality: 90, width: 950, height: 750)
114
+ kit.to_img(:png)
115
+ kit.to_file(image_name)
116
+
117
+ # Convert HTML to Image
118
+ # system ("wkhtmltoimage -f 'png' #{file_name} #{image_name}")
119
+ end
94
120
 
95
- self.asciidoc_to_html(@source, @destination, extensions, merged_options)
96
121
  else
97
122
  Hyla.logger.error ">> Unknow rendering"
98
123
  exit(1)
@@ -109,6 +134,10 @@ module Hyla
109
134
  return [Configuration::backends, 'haml', 'deckjs'] * '/'
110
135
  when 'revealjs'
111
136
  return [Configuration::backends, 'slim', 'revealjs'] * '/'
137
+ when 'html5'
138
+ return [Configuration::backends, 'slim', 'html5'] * '/'
139
+ else
140
+ return [Configuration::backends, 'slim', 'html5'] * '/'
112
141
  end
113
142
  end
114
143
 
@@ -135,6 +164,12 @@ module Hyla
135
164
  current_dir = Dir.pwd
136
165
  Hyla.logger.info ">> Current dir: #{current_dir}"
137
166
 
167
+ #
168
+ # Backup Asciidoctor attributes
169
+ # Strange issue discovered
170
+ #
171
+ @attributes_bk = options[:attributes]
172
+
138
173
  # Delete destination directory (generated_content, ...)
139
174
  # FileUtils.rm_rf(Dir.glob(@destination))
140
175
 
@@ -159,6 +194,9 @@ module Hyla
159
194
  Hyla.logger.info ">> Dir of html: #{html_dir}"
160
195
  FileUtils.mkdir_p html_dir
161
196
 
197
+ # Copy Fonts
198
+ self.cp_resources_to_dir(File.dirname(html_dir), 'fonts')
199
+
162
200
  # Copy Resources for Slideshow
163
201
  case options[:backend]
164
202
  when 'deckjs'
@@ -175,6 +213,7 @@ module Hyla
175
213
  html_file_name = file_name_processed.to_s.gsub(/.adoc$|.ad$|.asciidoc$|.index$|.txt$/, '.html')
176
214
  options[:to_dir] = html_dir
177
215
  options[:to_file] = html_file_name
216
+ options[:attributes] = @attributes_bk
178
217
  Asciidoctor.render_file(f, options)
179
218
 
180
219
  end
@@ -227,15 +266,13 @@ module Hyla
227
266
  # Expand File Path
228
267
  @out_dir = File.expand_path out_dir
229
268
 
230
- # Re Create Directory of generated content
231
- if Dir.exist? @out_dir
232
- FileUtils.rm_rf @out_dir
233
- FileUtils.mkdir_p @out_dir
234
- else
269
+ #
270
+ # Create destination directory if it does not exist
271
+ unless Dir.exist? @out_dir
235
272
  FileUtils.mkdir_p @out_dir
236
273
  end
237
274
 
238
- # Copy YML Config file
275
+ # Copy YAML Config file
239
276
  FileUtils.cp_r [Configuration::templates, Configuration::YAML_CONFIG_FILE_NAME] * '/', @out_dir
240
277
 
241
278
  # Copy styles
@@ -263,11 +300,15 @@ module Hyla
263
300
  #
264
301
  if line[/^=\s/]
265
302
 
266
- # Create File
303
+ #
304
+ # Create Directory of the module and next the File
305
+ #
267
306
  dir_name = remove_special_chars(2, line)
268
307
  new_dir = [@out_dir, dir_name].join('/')
308
+ FileUtils.rm_rf new_dir
309
+ FileUtils.mkdir new_dir
269
310
  Hyla.logger.info '>> Directory created : ' + new_dir + ' <<'
270
- FileUtils.mkdir_p new_dir
311
+
271
312
  Dir.chdir(new_dir)
272
313
 
273
314
  # Add image, audio, video directory
@@ -284,6 +325,21 @@ module Hyla
284
325
  @project_index_file.puts Configuration::INCLUDE_PREFIX + dir_name + '/' + dir_name + Configuration::INDEX_SUFFIX + Configuration::INCLUDE_SUFFIX
285
326
  @project_index_file.puts "\n"
286
327
 
328
+ #
329
+ # Generate a Module key value
330
+ # 01, 02, ...
331
+ # that we will use as key to create the asciidoc file
332
+ #
333
+ dir_name = File.basename(Dir.getwd)
334
+ @module_key = dir_name.initial.rjust(2, '0')
335
+ Hyla.logger.info ">> Module key : #@module_key <<"
336
+
337
+ #
338
+ # Reset counter value used to generate file number
339
+ # for the file 01, 00
340
+ #
341
+ @index = 0
342
+
287
343
  # Move to next line record
288
344
  next
289
345
  end
@@ -300,10 +356,22 @@ module Hyla
300
356
  @previous_f.close
301
357
  end
302
358
 
303
- # Create File
359
+ #
360
+ # Replace special characters form the file and
361
+ # add the module key followed by the index value for the file
362
+ # Example : m01p01_MyTitle.ad, m01p02_Another_Title.ad
363
+ #
304
364
  f_name = remove_special_chars(3, line)
365
+ @index += 1
366
+ #file_index = @index.to_s.initial.rjust(2, '0')
367
+ file_index = sprintf('%02d', @index)
368
+ f_name = 'm' + @module_key + 'p' + file_index + '_' + f_name + '.ad'
369
+
305
370
  Hyla.logger.info ' # File created : ' + f_name.to_s
306
- f_name += '.adoc'
371
+
372
+ #
373
+ # Create File and add configuration HEADER
374
+ #
307
375
  @new_f = File.new(f_name, 'w')
308
376
  @new_f.puts Configuration::HEADER
309
377
  @new_f.puts "\n"
@@ -326,6 +394,7 @@ module Hyla
326
394
 
327
395
  end
328
396
 
397
+ =begin
329
398
  #
330
399
  # Generate PDF
331
400
  #
@@ -333,9 +402,9 @@ module Hyla
333
402
  file_path = [source, html_file_name] * '/'
334
403
  html_file = File.new(file_path)
335
404
  kit = PDFKit.new(html_file,
336
- :page_size => 'A4',
337
- :toc => true,
338
- :page_offset => 1,
405
+ :page_size => 'A4',
406
+ :toc => true,
407
+ :page_offset => 1,
339
408
  :footer_center => 'Page [page]')
340
409
 
341
410
  # Create destination directory if it does not exist
@@ -344,10 +413,77 @@ module Hyla
344
413
  end
345
414
 
346
415
  # Save PDF to a file
347
- pdf_file_name = [destination, html_file_name.sub(/html|htm/,'pdf')] * '/'
416
+ pdf_file_name = [destination, html_file_name.sub(/html|htm/, 'pdf')] * '/'
348
417
  kit.to_file(pdf_file_name)
349
418
  Hyla.logger.info ">> PDF file generated and saved : #{pdf_file_name} "
350
419
  end
420
+ =end
421
+
422
+ def self.html_to_pdf(file_name, source, destination, footer_text, header_html_path, cover_path)
423
+
424
+ @cover_path = cover_path
425
+ destination= File.expand_path destination
426
+ pdf_file = [destination, "result.pdf"] * '/'
427
+ wkhtml_cmd = "wkhtmltopdf"
428
+ size = 'A4'
429
+
430
+ # pdf_file_name = [destination, html_file_name.sub(/html|htm/, 'pdf')] * '/'
431
+
432
+ list_of_files = ""
433
+
434
+ unless File.directory?(destination)
435
+ FileUtils.mkdir_p(destination)
436
+ end
437
+
438
+ if file_name.nil? || file_name.empty?
439
+ filter = [source] * '/' + "*.html"
440
+ files = Dir[filter]
441
+
442
+ files.each do |file|
443
+ file_name = File.basename file
444
+ next if file_name.downcase.include?('assessments')
445
+ next if file_name.downcase.include?('labinstructions')
446
+ next if file_name.downcase.include?('title')
447
+ next if file_name.downcase.include?('cover')
448
+ file = File.expand_path file
449
+ list_of_files = list_of_files + " " + file
450
+ end
451
+ else
452
+ #
453
+ # If the file passed as parameter has extension name equal to txt, then we will extract the file names
454
+ # whenever we have a include:: directive in the file
455
+ #
456
+ extension_name = File.extname file_name
457
+
458
+ case extension_name
459
+ when '.txt'
460
+ file_to_processed = [File.expand_path(Dir.getwd), file_name] * '/'
461
+ result = self.extract_file_names(file_to_processed, source)
462
+
463
+ result.each do | file_path |
464
+ if file_path.downcase.include?('title') || file_path.downcase.include?('cover')
465
+ @cover_path = file_path
466
+ next
467
+ end
468
+ list_of_files = list_of_files + " " + file_path
469
+ end
470
+
471
+ else
472
+ list_of_files = [File.expand_path(source), file_name] * '/'
473
+ end
474
+ end
475
+
476
+ wkhtml_cmd.concat " #{list_of_files} #{pdf_file}"
477
+ wkhtml_cmd.concat " --margin-top '18mm' --header-html '#{header_html_path}'" if header_html_path
478
+ wkhtml_cmd.concat " --margin-bottom '10mm' --footer-center '#{footer_text}'" if footer_text
479
+ wkhtml_cmd.concat " --cover '#@cover_path'" if @cover_path
480
+ wkhtml_cmd.concat " --page-size #{size}"
481
+ Hyla.logger.debug "c #{wkhtml_cmd}"
482
+
483
+ Dir.chdir(source) do
484
+ system "#{wkhtml_cmd}"
485
+ end
486
+ end
351
487
 
352
488
  #
353
489
  # Create Asset Directory
@@ -362,7 +498,9 @@ module Hyla
362
498
  # Remove space, dot from a String
363
499
  #
364
500
  def self.remove_special_chars(pos, text)
365
- return text[pos, text.length].strip.gsub(/\s/, '_').gsub('.', '')
501
+ return text[pos, text.length].strip.gsub(/\s/, '_')
502
+ .gsub('.', '')
503
+ .gsub('&', '')
366
504
  end
367
505
 
368
506
  #
@@ -410,6 +548,39 @@ module Hyla
410
548
  end
411
549
  end
412
550
 
551
+ #
552
+ # Extract files names from a file containing include:: directive
553
+ #
554
+ def self.extract_file_names(file_name, destination)
555
+
556
+ result = []
557
+ f = File.open(file_name, 'r')
558
+ matches = f.grep(Configuration::IncludeDirectiveRx)
559
+
560
+ if matches
561
+
562
+ matches.each do |record|
563
+ # Extract string after include::
564
+ matchdata = record.match(/^include::(.+)/)
565
+
566
+ if matchdata
567
+
568
+ data = matchdata[1]
569
+ # Remove []
570
+ name = data.to_s.gsub(/[\[\]]/, '').strip
571
+
572
+ # Rename file to .html
573
+ name = name.gsub(/ad$/, 'html')
574
+ file_name = [destination, name] * '/'
575
+ file_path = File.expand_path file_name
576
+ result << file_path
577
+ end
578
+ end
579
+ end
580
+ f.close
581
+ return result
582
+ end
583
+
413
584
  end # class
414
585
  end # module Commands
415
- end # module Hyla
586
+ end # module Hyla