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
@@ -1,30 +1,39 @@
1
1
  module RevealCK
2
2
  #
3
- # Public: A Presentation is an ordered list of slides. It provides
4
- # access to the content of the slides on demand. It it also the
5
- # mechanism by which the slide "dsl" is defined and loaded into
6
- # being.
3
+ # Public: A Presentation is slide html and metadata. Access html via
4
+ # #html. Access metadata via theme, title, author, transition.
7
5
  #
8
6
  class Presentation
9
7
 
10
- attr_accessor :theme, :title, :author
8
+ include Config
9
+
10
+ attr_accessor :html
11
11
 
12
12
  def initialize
13
- @slides = []
14
- @theme = 'default'
13
+ @html = ''
14
+ end
15
+
16
+ def add(content)
17
+ @html << content.html
18
+ end
19
+
20
+ def self.from_template(path)
21
+ presentation = Presentation.new
22
+ template = Templates::Processor.open path
23
+ presentation.html = template.output({})
24
+ presentation
15
25
  end
16
26
 
17
- def add_slide(slide)
18
- @slides << slide
27
+ def self.from_dsl(path)
28
+ RevealCK::PresentationDSL.load path
19
29
  end
20
30
 
21
- def content
22
- content = ''
23
- @slides.each do |slide|
24
- content << slide.html
25
- content << "\n\n"
31
+ def self.load(path)
32
+ if path.end_with? '.rb'
33
+ Presentation.from_dsl path
34
+ else
35
+ Presentation.from_template path
26
36
  end
27
- content
28
37
  end
29
38
 
30
39
  end
@@ -5,35 +5,44 @@ module RevealCK
5
5
  #
6
6
  class PresentationDSL
7
7
 
8
+ attr_reader :author, :title, :theme, :transition
9
+
8
10
  def initialize
9
11
  @slides = []
10
12
  end
11
13
 
12
- def theme(theme = 'default')
14
+ def theme(theme)
13
15
  @theme = theme
14
16
  end
15
17
 
16
- def title(title = 'Slides')
18
+ def transition(transition)
19
+ @transition = transition
20
+ end
21
+
22
+ def title(title)
17
23
  @title = title
18
24
  end
19
25
 
20
- def author(author = '')
26
+ def author(author)
21
27
  @author = author
22
28
  end
23
29
 
24
- def slide(template, variables)
30
+ def slide(template, variables = {})
25
31
  variables[:template] = template
26
32
  @slides << RevealCK::Slide.new(variables)
27
33
  end
28
34
 
35
+ def contents_of(path)
36
+ File.open(path).read
37
+ end
38
+
29
39
  def build
30
40
  presentation = RevealCK::Presentation.new
31
- presentation.theme = @theme
32
- presentation.author = @author
33
- presentation.title = @title
34
- @slides.each do |slide|
35
- presentation.add_slide slide
36
- end
41
+ presentation.theme = @theme if @theme
42
+ presentation.transition = @transition if @transition
43
+ presentation.author = @author if @author
44
+ presentation.title = @title if @title
45
+ @slides.each { |slide| presentation.add slide }
37
46
  presentation
38
47
  end
39
48
 
@@ -46,8 +55,7 @@ module RevealCK
46
55
  def self.load(file)
47
56
  builder = PresentationDSL.new
48
57
  contents = File.open(file).read
49
- result = builder.instance_eval contents
50
- result
58
+ builder.instance_eval(contents)
51
59
  end
52
60
 
53
61
  end
@@ -7,13 +7,13 @@ module RevealCK
7
7
 
8
8
  def initialize(args)
9
9
  template = args[:template] || raise(':template is required')
10
- file = TemplateFinder.new.find template
11
- @template = TemplateProcessor.open file
10
+ file = Templates::Finder.new.find template
11
+ @template = Templates::Processor.open file
12
12
  @variables = args
13
13
  end
14
14
 
15
15
  def html
16
- @template.output({}, @variables)
16
+ @template.output(@variables)
17
17
  end
18
18
 
19
19
  end
@@ -0,0 +1,3 @@
1
+ require_relative 'templates/finder'
2
+ require_relative 'templates/render_scope'
3
+ require_relative 'templates/processor'
@@ -0,0 +1,35 @@
1
+ module RevealCK
2
+ module Templates
3
+ #
4
+ # Public: This class is home to a simple algorithm for looking up
5
+ # files in a series of directories. Directory order matters, and the
6
+ # first match for the file will be returned. It'll raise if it can't
7
+ # find the file you've asked for.
8
+ #
9
+ class Finder
10
+
11
+ attr_reader :paths
12
+
13
+ def initialize(args = {})
14
+ @paths = args[:paths] || default_paths
15
+ end
16
+
17
+ def default_paths
18
+ pwd_templates = File.join Dir.pwd, 'templates'
19
+ reveal_ck_templates = File.join RevealCK::LOCATION, 'templates'
20
+ [pwd_templates, reveal_ck_templates]
21
+ end
22
+
23
+ def find(template_name)
24
+ paths.each do |path|
25
+ glob_pattern = "#{File.join(path, template_name)}*"
26
+ Dir.glob(glob_pattern).each do |match|
27
+ return match unless File.directory? match
28
+ end
29
+ end
30
+ raise "Unable to find #{template_name} in #{paths}"
31
+ end
32
+
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,32 @@
1
+ #
2
+ # Setup Slim
3
+ require 'slim'
4
+ ::Slim::Engine.set_default_options pretty: true
5
+
6
+ module RevealCK
7
+ module Templates
8
+ #
9
+ # Public: A Processor is given a template and expected to render
10
+ # it.
11
+ #
12
+ class Processor
13
+
14
+ require 'tilt'
15
+
16
+ def initialize(file)
17
+ @template = Tilt.new file
18
+ end
19
+
20
+ def output(locals = {})
21
+ scope = RenderScope.new
22
+ @template.render scope, locals
23
+ end
24
+
25
+ def self.open(file)
26
+ Processor.new file
27
+ end
28
+
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,14 @@
1
+ module RevealCK
2
+ module Templates
3
+ #
4
+ # Public: A new instance of RenderScope is created and made
5
+ # available when templates are rendered. Instance methods on it
6
+ # are availale to templates.
7
+ #
8
+ class RenderScope
9
+ def contents_of(path)
10
+ File.open(path).read
11
+ end
12
+ end
13
+ end
14
+ end
@@ -1,3 +1,3 @@
1
1
  module RevealCK
2
- VERSION = '0.1.6'
2
+ VERSION = '0.1.7'
3
3
  end
@@ -0,0 +1,7 @@
1
+ desc 'Exercise reveal-ck examples'
2
+ task :examples do
3
+ examples = FileList["examples/*"]
4
+ examples.each do |example|
5
+ load example
6
+ end
7
+ end
File without changes
File without changes
File without changes
@@ -0,0 +1,7 @@
1
+ title = "The Never Sea Slides"
2
+ author = "Captain Hook"
3
+
4
+ [presentation]
5
+
6
+ theme = "night"
7
+ transition = "page"
@@ -0,0 +1 @@
1
+ title = "The Never Sea Slides"
@@ -0,0 +1,2 @@
1
+ %section
2
+ slides.haml
@@ -0,0 +1,5 @@
1
+ presentation do
2
+ theme 'night'
3
+ slide 'text',
4
+ content: 'slides.rb'
5
+ end
@@ -3,10 +3,14 @@ presentation do
3
3
  title 'Presentation Title'
4
4
  author 'Presentation Author'
5
5
  theme 'night'
6
+ transition 'page'
6
7
 
7
8
  slide 'text',
8
9
  content: 'Hello World'
9
10
 
11
+ slide 'code',
12
+ content: contents_of('lib/reveal-ck.rb')
13
+
10
14
  slide 'text',
11
15
  content: 'Thanks!'
12
16
 
@@ -0,0 +1,3 @@
1
+ def two
2
+ 2
3
+ end
File without changes
File without changes
@@ -0,0 +1,2 @@
1
+ Whatever you can do or dream you can, begin it. Boldness has genius,
2
+ power and magic in it.
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'examples/programmatic_slides.rb' do
4
+
5
+ it 'prints output from a presentation with several slides' do
6
+ expect($stdout).to receive :puts
7
+ expect {
8
+ load 'examples/programmatic_slides.rb'
9
+ }.to_not raise_error
10
+ end
11
+
12
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'examples/slide_output.rb' do
4
+
5
+ it 'prints output from a single slide' do
6
+ expect($stdout).to receive :puts
7
+ expect {
8
+ load 'examples/slide_output.rb'
9
+ }.to_not raise_error
10
+ end
11
+
12
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+
3
+ module RevealCK
4
+ module Builders
5
+
6
+ describe Builder, 'when subclassed' do
7
+
8
+ it 'requires that subclasses implement #register_tasks' do
9
+ class BadBuilder < Builder; end
10
+ bad_builder = BadBuilder.new
11
+ expect { bad_builder.register_tasks }.to raise_error
12
+ end
13
+
14
+ it 'invokes each registered task when it receives #build' do
15
+
16
+ class TestBuilder < Builder
17
+
18
+ attr_reader :value
19
+
20
+ def initialize
21
+ @value = 0
22
+ end
23
+
24
+ def register_tasks
25
+ @tasks = []
26
+ @value = 0
27
+ add_task 'Set Value to 1' do
28
+ @value = 1
29
+ end
30
+ end
31
+ end
32
+
33
+ test_builder = TestBuilder.new
34
+ test_builder.build!
35
+ expect(test_builder.value).to eq 1
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,39 @@
1
+ require 'spec_helper'
2
+ require 'tmpdir'
3
+
4
+ module RevealCK
5
+ module Builders
6
+ describe PackagedSlides do
7
+
8
+ let :presentation do
9
+ presentation = Presentation.new
10
+ presentation.title = "Presentation Title"
11
+ presentation.author = "Presentation Author"
12
+
13
+ presentation.add(Slide.new({
14
+ template: 'intro',
15
+ title: presentation.title,
16
+ author: presentation.author,
17
+ site: 'http://site.com',
18
+ twitter: 'twitter'
19
+ }))
20
+ presentation
21
+ end
22
+
23
+ it 'can build reveal.js slides from a Presentation' do
24
+
25
+ tmp_dir = Dir.mktmpdir
26
+
27
+ packaged_slides =
28
+ PackagedSlides.new({
29
+ presentation: presentation,
30
+ output_dir: tmp_dir,
31
+ })
32
+ packaged_slides.build!
33
+
34
+ expect(File.exists? File.join(tmp_dir, "index.html")).to be_true
35
+ end
36
+
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+ require 'fileutils'
3
+ require 'tmpdir'
4
+
5
+ module RevealCK
6
+ module Changers
7
+ describe Slicer do
8
+
9
+ describe '.remove!' do
10
+
11
+ let :before_remove do
12
+ spec_data 'changers', 'slicer', 'before_remove'
13
+ end
14
+
15
+ let :after_remove do
16
+ spec_data 'changers', 'slicer', 'after_remove'
17
+ end
18
+
19
+ it 'removes a range of lines from a file' do
20
+ Dir.mktmpdir do |tmp_dir|
21
+ FileUtils.cp before_remove, tmp_dir
22
+ test_file = File.join tmp_dir, 'before_remove'
23
+ Slicer.remove! test_file, 3..6
24
+ test_file_contents = File.open(test_file).read
25
+ after_remove_contents = File.open(after_remove).read
26
+ test_file_contents.should == after_remove_contents
27
+ end
28
+ end
29
+ end
30
+
31
+ describe '#remove' do
32
+
33
+ it 'returns lines with the range removed' do
34
+ lines = [
35
+ 'a',
36
+ 'b',
37
+ 'c',
38
+ 'd'
39
+ ]
40
+ slicer = Slicer.new lines
41
+ slicer.remove(1..2).should == ['a', 'd']
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end