reveal-ck 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +8 -8
  2. data/bin/reveal-ck +18 -12
  3. data/lib/reveal-ck.rb +3 -10
  4. data/lib/reveal-ck/builders.rb +4 -0
  5. data/lib/reveal-ck/builders/build_task.rb +21 -0
  6. data/lib/reveal-ck/builders/builder.rb +27 -0
  7. data/lib/reveal-ck/builders/index_html.rb +85 -0
  8. data/lib/reveal-ck/builders/packaged_slides.rb +84 -0
  9. data/lib/reveal-ck/changers.rb +3 -0
  10. data/lib/reveal-ck/changers/slicer.rb +25 -0
  11. data/lib/reveal-ck/changers/splicer.rb +37 -0
  12. data/lib/reveal-ck/changers/string_replacer.rb +18 -0
  13. data/lib/reveal-ck/config.rb +51 -23
  14. data/lib/reveal-ck/presentation.rb +24 -15
  15. data/lib/reveal-ck/presentation_dsl.rb +20 -12
  16. data/lib/reveal-ck/slide.rb +3 -3
  17. data/lib/reveal-ck/templates.rb +3 -0
  18. data/lib/reveal-ck/templates/finder.rb +35 -0
  19. data/lib/reveal-ck/templates/processor.rb +32 -0
  20. data/lib/reveal-ck/templates/render_scope.rb +14 -0
  21. data/lib/reveal-ck/version.rb +1 -1
  22. data/rakelib/examples.rake +7 -0
  23. data/spec/data/{slicer → changers/slicer}/after_remove +0 -0
  24. data/spec/data/{slicer → changers/slicer}/before_remove +0 -0
  25. data/spec/data/{splicer → changers/splicer}/abcd +0 -0
  26. data/spec/data/{splicer → changers/splicer}/after_insert +0 -0
  27. data/spec/data/{splicer → changers/splicer}/before_insert +0 -0
  28. data/spec/data/{string_replacer → changers/string_replacer}/after_replace +0 -0
  29. data/spec/data/{string_replacer → changers/string_replacer}/before_replace +0 -0
  30. data/spec/data/config/full_config.toml +7 -0
  31. data/spec/data/config/partial_config.toml +1 -0
  32. data/spec/data/presentation/slides.haml +2 -0
  33. data/spec/data/presentation/slides.rb +5 -0
  34. data/spec/data/{dsl/slides.rb → presentation_dsl/dsl.rb} +4 -0
  35. data/spec/data/templates/finder/code/function.rb +3 -0
  36. data/spec/data/{template_finder/automated/automated.slim → templates/finder/quotes/create} +0 -0
  37. data/spec/data/{template_finder/automated/common.haml → templates/finder/templates/template_one.slim} +0 -0
  38. data/spec/data/{template_finder/custom/common.haml → templates/finder/templates/template_two.slim} +0 -0
  39. data/spec/data/{template_finder/custom/custom.slim → templates/finder/templates/text.slim} +0 -0
  40. data/spec/data/{haml → templates/processor}/basic.haml +0 -0
  41. data/spec/data/{slim → templates/processor}/basic.slim +0 -0
  42. data/spec/data/templates/render_scope/quote +2 -0
  43. data/spec/examples/programmatic_slides_spec.rb +12 -0
  44. data/spec/examples/slide_output_spec.rb +12 -0
  45. data/spec/lib/reveal-ck/builders/builder_spec.rb +39 -0
  46. data/spec/lib/reveal-ck/builders/packaged_slides_spec.rb +39 -0
  47. data/spec/lib/reveal-ck/changers/slicer_spec.rb +46 -0
  48. data/spec/lib/reveal-ck/changers/splicer_spec.rb +45 -0
  49. data/spec/lib/reveal-ck/changers/string_replacer_spec.rb +35 -0
  50. data/spec/lib/reveal-ck/config_spec.rb +68 -20
  51. data/spec/lib/reveal-ck/presentation_dsl_spec.rb +21 -11
  52. data/spec/lib/reveal-ck/presentation_spec.rb +40 -38
  53. data/spec/lib/reveal-ck/slide_spec.rb +3 -3
  54. data/spec/lib/reveal-ck/templates/finder_spec.rb +88 -0
  55. data/spec/lib/reveal-ck/templates/processor_spec.rb +31 -0
  56. data/spec/lib/reveal-ck/templates/render_scope_spec.rb +24 -0
  57. data/templates/{title.slim → intro.slim} +0 -0
  58. metadata +77 -71
  59. data/lib/reveal-ck/build_task.rb +0 -19
  60. data/lib/reveal-ck/builder.rb +0 -25
  61. data/lib/reveal-ck/file_slicer.rb +0 -23
  62. data/lib/reveal-ck/file_splicer.rb +0 -36
  63. data/lib/reveal-ck/file_string_replacer.rb +0 -16
  64. data/lib/reveal-ck/presentation_builder.rb +0 -94
  65. data/lib/reveal-ck/slide_builder.rb +0 -81
  66. data/lib/reveal-ck/slides_html_builder.rb +0 -39
  67. data/lib/reveal-ck/template_finder.rb +0 -33
  68. data/lib/reveal-ck/template_processor.rb +0 -28
  69. data/spec/data/config/config.toml +0 -6
  70. data/spec/data/html/converted_basic_haml.html +0 -10
  71. data/spec/data/html/converted_basic_slim.html +0 -10
  72. data/spec/data/html/reveal-js-index.html +0 -375
  73. data/spec/data/slides_html_builder/slides.haml +0 -3
  74. data/spec/data/slides_html_builder/slides.rb +0 -14
  75. data/spec/data/slides_html_builder/slides.slim +0 -2
  76. data/spec/lib/reveal-ck/builder_spec.rb +0 -37
  77. data/spec/lib/reveal-ck/file_slicer_spec.rb +0 -44
  78. data/spec/lib/reveal-ck/file_splicer_spec.rb +0 -43
  79. data/spec/lib/reveal-ck/file_string_replacer_spec.rb +0 -34
  80. data/spec/lib/reveal-ck/presentation_builder_spec.rb +0 -37
  81. data/spec/lib/reveal-ck/slides_html_builder_spec.rb +0 -102
  82. data/spec/lib/reveal-ck/template_finder_spec.rb +0 -87
  83. data/spec/lib/reveal-ck/template_processor_spec.rb +0 -29
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NjdkMTYxMjE5OGFhMDQ5ZmNiMzdhYWQwZGYwOGM3NTQ4NmNhYmYzOA==
4
+ NmVmNmUyNjhkZjI2MjM3ODBhZTQ2MzJhMDY1YTYyZWM3NjE3ZjFjOA==
5
5
  data.tar.gz: !binary |-
6
- NTU5OTMwZGI1NTc5OTJjNDc1MDk4YTFlNjY4NjA1ZWJhZGRkZjI2YQ==
6
+ NDdlZGYyMGRjZmMxYTliMTY3ODg0MmZlZWY3YzQ4MGY3Y2U3ZWE2OQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- M2E1N2FlMzVhM2JmMWU0M2YzYmMwYzIwNGZjMzYxY2U3NGY0MWQzYWM0NmVh
10
- M2RiOTE0NTRiYjJiMzRmYWUwOWE1Y2IyMDI1ZmE4ZDQyODA4OTQzZjRhOTg3
11
- ZmEzNmU5OTJiYTFhZjRiNTNjMDA3ZjViZjg2YmQzZGU2NTJjYmE=
9
+ ZTQ4MjA3M2U3ZDQ0MWJhMWZiOGI2NTA1ZDJmY2M0ZTczYmQ5MDE1MThmMDZj
10
+ ZmU2YThkOTM4YzE4YmQzNDgzNzZhMDVkYTQ4ZDRiMjQ0MGNmZDY0NzM2MTFk
11
+ Y2M4NjIwYTAzNTEwODBkMjU4YTJlNWJjNzFkZGFhZjZiODc1MTM=
12
12
  data.tar.gz: !binary |-
13
- ZTNiOTVhZDNhOGE5ZWExYmUzM2Y2MTM5Njk2YjhiZWM5OTVkZjYyZDNkOWJl
14
- MmE0OGQ4NjFhOWQwNDg2NzBjOTZjOTA5YWRiZDk5NGUyYjcwMmQ3MTdiM2Zm
15
- YmY5MjUwMTJlOTY0NzVmOGIwNjlkZTMwZjQ0ODI2ZWJmM2I1NTE=
13
+ ZjcwODAyYzA3ZWQ5MGVlMzEzYmI0MmRhMjlmYmY5ZDYxZjcyZjhkZDQ0OWEy
14
+ MmMxNzhjYTUzNjk2N2IwZWI0MTYwYzkwZjQ5MjZkMDgzNDU1OWFhZDIwMzRm
15
+ NTFmM2FkNmZmYWIyZTc3MzRiMWIwMGE5NGMyZGM3NjFiNzRlNDg=
data/bin/reveal-ck CHANGED
@@ -10,28 +10,34 @@ version RevealCK::VERSION
10
10
 
11
11
  desc 'Generate reveal.js slides'
12
12
  command :generate do |c|
13
+
14
+ # Where is the slides file?
15
+ default_file = 'slides.haml' if File.exists? 'slides.haml'
16
+ default_file = 'slides.slim' if File.exists? 'slides.slim'
17
+ default_file = 'slides.rb' if File.exists? 'slides.rb'
18
+ c.desc 'The file containing your slides'
19
+ c.flag [:f, :file], default_value: default_file
20
+
13
21
  c.action do |global_options,options,args|
22
+ slides_file = options[:file]
14
23
 
15
24
  require 'rake' # for FileList
16
-
17
25
  image_files = FileList["images/**/*"]
18
26
 
19
27
  output_dir = 'slides'
20
28
 
21
- slides_file = 'slides.haml' if File.exists? 'slides.haml'
22
- slides_file = 'slides.slim' if File.exists? 'slides.slim'
23
- slides_file = 'slides.rb' if File.exists? 'slides.rb'
29
+ presentation = RevealCK::Presentation.load slides_file
24
30
 
25
- config = RevealCK::Config.new config_file: 'config.toml'
31
+ if File.exists? 'config.toml'
32
+ presentation.merge_config file: 'config.toml'
33
+ end
26
34
 
27
- builder = RevealCK::PresentationBuilder.new({
28
- image_files: image_files,
29
- output_dir: output_dir,
30
- slides_file: slides_file,
31
- config: config
32
- })
35
+ builder = RevealCK::Builders::PackagedSlides.new({
36
+ image_files: image_files,
37
+ output_dir: output_dir,
38
+ presentation: presentation
39
+ })
33
40
  builder.build!
34
-
35
41
  end
36
42
  end
37
43
 
data/lib/reveal-ck.rb CHANGED
@@ -1,18 +1,11 @@
1
1
  require_relative 'reveal-ck/version'
2
2
  require_relative 'reveal-ck/config'
3
- require_relative 'reveal-ck/file_string_replacer'
4
- require_relative 'reveal-ck/file_slicer'
5
- require_relative 'reveal-ck/file_splicer'
6
- require_relative 'reveal-ck/template_finder'
7
- require_relative 'reveal-ck/template_processor'
8
3
  require_relative 'reveal-ck/slide'
9
4
  require_relative 'reveal-ck/presentation'
10
- require_relative 'reveal-ck/build_task'
11
- require_relative 'reveal-ck/builder'
12
- require_relative 'reveal-ck/slides_html_builder'
13
- require_relative 'reveal-ck/slide_builder'
14
- require_relative 'reveal-ck/presentation_builder'
15
5
  require_relative 'reveal-ck/presentation_dsl'
6
+ require_relative 'reveal-ck/templates'
7
+ require_relative 'reveal-ck/changers'
8
+ require_relative 'reveal-ck/builders'
16
9
 
17
10
  # RevealCK::LOCATION is the path where reveal-ck is residing on your
18
11
  # system as a gem.
@@ -0,0 +1,4 @@
1
+ require_relative 'builders/build_task'
2
+ require_relative 'builders/builder'
3
+ require_relative 'builders/index_html'
4
+ require_relative 'builders/packaged_slides'
@@ -0,0 +1,21 @@
1
+ module RevealCK
2
+ module Builders
3
+ #
4
+ # Public: A BuildTask couple a written description (in the form of a
5
+ # string) with an action in (the form of a proc). It executes the
6
+ # proc on demand via go!
7
+ #
8
+ class BuildTask
9
+
10
+ def initialize(description, action)
11
+ @description = description
12
+ @action = action
13
+ end
14
+
15
+ def go
16
+ @action.call
17
+ end
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,27 @@
1
+ module RevealCK
2
+ module Builders
3
+ #
4
+ # Public: A Builder knows how to execute BuildTasks. These are added
5
+ # via add_task, and executed via build!
6
+ #
7
+ # It is expected to be subclassed, and the subclass must override
8
+ # register_tasks.
9
+ #
10
+ class Builder
11
+
12
+ def register_tasks
13
+ raise 'Subclasses must implement register_tasks'
14
+ end
15
+
16
+ def add_task(description, &action)
17
+ @tasks << BuildTask.new(description, action)
18
+ end
19
+
20
+ def build!
21
+ register_tasks unless @tasks
22
+ @tasks.each { |task| task.go }
23
+ end
24
+
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,85 @@
1
+ module RevealCK
2
+ module Builders
3
+ #
4
+ # Public: An IndexHtml knows how to build the index.html file (the
5
+ # core slides) within a reveal.js presentation.
6
+ #
7
+ class IndexHtml < Builder
8
+
9
+ attr_reader :user_slides, :reveal_slides
10
+
11
+ attr_reader :tasks
12
+
13
+ attr_reader :config
14
+
15
+ def initialize(args)
16
+ @user_slides = args[:user_slides]
17
+ @reveal_slides = args[:reveal_slides]
18
+ @config = args[:config]
19
+ end
20
+
21
+ private
22
+
23
+ def register_tasks
24
+
25
+ @tasks = []
26
+
27
+ remove_default_content reveal_slides
28
+ add_user_content reveal_slides, user_slides
29
+ replace_title reveal_slides, config.title
30
+ replace_author reveal_slides, config.author
31
+ replace_theme reveal_slides, config.theme
32
+ replace_transition reveal_slides, config.transition
33
+ end
34
+
35
+ def remove_default_content(file)
36
+ add_task 'Slicing out reveal.js default slides' do
37
+ begin_line_num = 38 # Line where I see <div class="slides">
38
+ end_line_num = 346 # Closing <div>
39
+ default_slides = begin_line_num..end_line_num
40
+ Changers::Slicer.remove! file, default_slides
41
+ end
42
+ end
43
+
44
+ def add_user_content(file, user_slides)
45
+ add_task "Splicing in slides from #{user_slides}" do
46
+ Changers::Splicer.insert!(user_slides,
47
+ into: file,
48
+ after: '<div class="slides">')
49
+ end
50
+ end
51
+
52
+ def replace_title(file, title)
53
+ old = 'reveal.js - The HTML Presentation Framework'
54
+ new = title
55
+ add_task 'Replacing the <title>' do
56
+ Changers::StringReplacer.replace! file, old: old, new: new
57
+ end
58
+ end
59
+
60
+ def replace_author(file, author)
61
+ old = 'name="author" content="Hakim El Hattab"'
62
+ new = 'name="author" content="' + author + '"'
63
+ add_task "Replacing the <meta name='author'>" do
64
+ Changers::StringReplacer.replace! file, old: old, new: new
65
+ end
66
+ end
67
+
68
+ def replace_theme(file, theme)
69
+ old = 'href="css/theme/default.css" id="theme"'
70
+ new = 'href="css/theme/' + theme + '.css" id="theme"'
71
+ add_task 'Replacing the core theme' do
72
+ Changers::StringReplacer.replace! file, old: old, new: new
73
+ end
74
+ end
75
+
76
+ def replace_transition(file, transition)
77
+ old = "Reveal.getQueryHash().transition || 'default'"
78
+ new = "Reveal.getQueryHash().transition || '#{transition}'"
79
+ add_task 'Replacing the core transition' do
80
+ Changers::StringReplacer.replace! file, old: old, new: new
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,84 @@
1
+ require 'fileutils'
2
+
3
+ module RevealCK
4
+ module Builders
5
+ #
6
+ # Public: A PackagedSlides knows how to bundle together all of the
7
+ # various files that makeup a reveal.js presentation.
8
+ #
9
+ class PackagedSlides < Builder
10
+
11
+ attr_reader :image_files, :tasks
12
+
13
+ def initialize(args)
14
+ @presentation =
15
+ args[:presentation] || raise(':presentation is required')
16
+ @image_files = args[:image_files]
17
+ @output_dir = args[:output_dir]
18
+ end
19
+
20
+ def output_dir(child = nil)
21
+ if child
22
+ File.join(@output_dir, child)
23
+ else
24
+ @output_dir
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ def register_tasks
31
+ @tasks = []
32
+ slides_html = output_dir 'slides.html'
33
+ create_dir output_dir
34
+ write_slides_html @presentation, slides_html
35
+ bundle_revealjs output_dir
36
+ bundle_image_files image_files, output_dir('images')
37
+ create_index_html slides_html, output_dir('index.html'), @presentation
38
+ end
39
+
40
+ def create_dir(dir)
41
+ add_task "Ensuring #{dir}/ exists" do
42
+ FileUtils.mkdir_p dir, verbose: false
43
+ end
44
+ end
45
+
46
+ def write_slides_html(presentation, slides_html)
47
+ add_task "Writing Presentation to '#{slides_html}'" do
48
+ File.open(slides_html, 'w') { |file| file << presentation.html }
49
+ end
50
+ end
51
+
52
+ def bundle_revealjs(output_dir)
53
+ add_task "Bundling up the revealjs stuff into #{output_dir}/" do
54
+ FileUtils.cp_r(RevealCK::REVEALJS_FILES,
55
+ output_dir,
56
+ verbose: false)
57
+ end
58
+ end
59
+
60
+ def bundle_image_files(image_files, image_output_dir)
61
+ if image_files
62
+ add_task "Copying in images into '#{image_output_dir}'" do
63
+ FileUtils.mkdir_p(image_output_dir, verbose: false)
64
+ FileUtils.cp_r(image_files,
65
+ image_output_dir,
66
+ verbose: false)
67
+ end
68
+ end
69
+ end
70
+
71
+ def create_index_html(slides_html, index_html, config)
72
+ add_task 'Creating slides/index.html' do
73
+ slide_builder =
74
+ IndexHtml.new({
75
+ user_slides: slides_html,
76
+ reveal_slides: index_html,
77
+ config: config
78
+ })
79
+ slide_builder.build!
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,3 @@
1
+ require_relative 'changers/string_replacer'
2
+ require_relative 'changers/slicer'
3
+ require_relative 'changers/splicer'
@@ -0,0 +1,25 @@
1
+ module RevealCK
2
+ module Changers
3
+ #
4
+ # Public: A Slicer knows how to remove a section of a file.
5
+ #
6
+ class Slicer
7
+
8
+ def self.remove!(slice_file, range)
9
+ lines = File.open(slice_file).readlines
10
+ slicer = Slicer.new lines
11
+ sliced_lines = slicer.remove range
12
+ File.open(slice_file, 'w') { |file| file << sliced_lines.join }
13
+ end
14
+
15
+ def initialize(lines)
16
+ @lines = lines
17
+ end
18
+
19
+ def remove(range)
20
+ @lines.select.with_index { |line, index| ! range.cover? index }
21
+ end
22
+
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,37 @@
1
+ module RevealCK
2
+ module Changers
3
+ #
4
+ # Public: A Splicer knows how to insert a list of lines into a file.
5
+ #
6
+ class Splicer
7
+
8
+ def initialize(lines)
9
+ @lines = lines
10
+ end
11
+
12
+ def insert(new_lines, opts)
13
+ index = @lines.each.with_index do |line, i|
14
+ break i + 1 if line.include? opts[:after]
15
+ end
16
+ @lines.insert(index, new_lines).flatten
17
+ end
18
+
19
+ def self.insert!(to_insert, opts)
20
+ to_insert_lines = readlines to_insert
21
+ insert_into_file = opts[:into]
22
+ insert_into_lines = readlines insert_into_file
23
+
24
+ splicer = Splicer.new insert_into_lines
25
+ spliced_lines = splicer.insert to_insert_lines, after: opts[:after]
26
+ File.open(insert_into_file, 'w') { |file| file << spliced_lines.join }
27
+ end
28
+
29
+ private
30
+
31
+ def self.readlines(file)
32
+ File.open(file).readlines
33
+ end
34
+
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,18 @@
1
+ module RevealCK
2
+ module Changers
3
+ #
4
+ # Public: A StringReplacer knows how to replace one string in a file
5
+ # with another.
6
+ #
7
+ class StringReplacer
8
+
9
+ def self.replace!(file, args)
10
+ old, new = args[:old], args[:new]
11
+ lines = File.open(file).read
12
+ lines = lines.sub old, new
13
+ File.open(file, 'w') { |file| file << lines }
14
+ end
15
+
16
+ end
17
+ end
18
+ end
@@ -2,47 +2,75 @@ require 'toml'
2
2
 
3
3
  module RevealCK
4
4
  #
5
- # Public: A Config knows about the core configuration values of a
6
- # RevealCK Presentation: title, author, theme, etc. It knows about
7
- # sensible defaults, and it can read these from a toml file.
5
+ # Public: The Config module supports the core metadata surrounding a
6
+ # RevealCK Presentation: title, author, theme, and transition.
8
7
  #
9
- class Config
8
+ module Config
10
9
 
11
- def initialize(args = {})
12
- config_file = args[:config_file]
13
- @config = load_config config_file
10
+ def author
11
+ @author || DEFAULTS['author']
12
+ end
13
+
14
+ def author=(author)
15
+ @author = author
14
16
  end
15
17
 
16
18
  def title
17
- @config['title']
19
+ @title || DEFAULTS['title']
18
20
  end
19
21
 
20
- def author
21
- @config['author']
22
+ def title=(title)
23
+ @title = title
22
24
  end
23
25
 
24
26
  def theme
25
- @config['presentation']['theme']
27
+ @theme || DEFAULTS['theme']
26
28
  end
27
29
 
28
- private
30
+ def theme=(theme)
31
+ @theme = theme
32
+ end
33
+
34
+ def transition
35
+ @transition || DEFAULTS['transition']
36
+ end
37
+
38
+ def transition=(transition)
39
+ @transition = transition
40
+ end
29
41
 
30
42
  DEFAULTS = {
31
- 'title' => 'Slides',
32
- 'author' => 'Hakim El Hattab',
33
- 'presentation' => {
34
- 'theme' => 'default'
35
- }
43
+ 'title' => 'Slides',
44
+ 'author' => '',
45
+ 'theme' => 'default',
46
+ 'transition' => 'default'
36
47
  }
37
48
 
38
- def load_config(config_file)
39
- config = DEFAULTS.dup
40
- if config_file && File.exists?(config_file)
41
- file_config = TOML.load_file config_file
42
- config.merge! file_config
49
+ def merge_config(args)
50
+ file = args[:file] || raise(':file is required')
51
+ config = TOML.load_file file
52
+
53
+ if config['author']
54
+ @author = config['author'] unless @author
55
+ end
56
+
57
+ if config['title']
58
+ @title = config['title'] unless @title
59
+ end
60
+
61
+ if config['presentation']
62
+ presentation = config['presentation']
63
+ if presentation['theme']
64
+ @theme = presentation['theme'] unless @theme
65
+ end
66
+
67
+ if presentation['transition']
68
+ @transition = presentation['transition'] unless @transition
69
+ end
43
70
  end
44
- config
71
+
45
72
  end
46
73
 
47
74
  end
75
+
48
76
  end