slide_hero 0.0.9 → 0.0.10

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: d4ab8f64da24ee4cbcb91a7f8d392e2593f22eae
4
- data.tar.gz: 4d1ea35db58b8ccec969d1a701170fd14e48733a
3
+ metadata.gz: eea8fd7d40b7ac15991d031fa339c5a685639c8f
4
+ data.tar.gz: af7ac4484b30e27993015101cdcbafbb42a44e33
5
5
  SHA512:
6
- metadata.gz: 916b941004ac4f84c4be11503ae1962c05179855053f1b799938b9ba4122fbdfe47620fe27b56549d3a1cd45f50761cf33548ee7ca4f1d442ab9af426008ef17
7
- data.tar.gz: f5ee06ef353fc4aeaf4b75022f8ab891852c024792b3c9aaae395c5fa419e308c4638d275475115abe7914829bedcee004792c29897ffa0d889b19651c55d3fd
6
+ metadata.gz: 784cc104067b250611f492d567de86a9df8e5020e0a41ec0651683152661d6f8805928cc77bbbdcc15906603fd528aff02c715abc42eae5596199d7f1fe0c0cf
7
+ data.tar.gz: 4a4b6a552bcbcfd2c64a646fd4625c3c0f34b2c47a6969835c610fdf91261aab0c7b472650cc07168bdd46a6d553b127a7e6c76271f52b44258e9cb722317171
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- ruby '2.2.0'
1
+ ruby '2.2.1'
2
2
  source 'https://rubygems.org'
3
3
 
4
4
  # Specify your gem's dependencies in slide_hero.gemspec
data/README.md CHANGED
@@ -102,12 +102,32 @@ this one slide. Any css color will work.
102
102
 
103
103
  ```ruby
104
104
  presentation "My Presentation" do
105
- slide "A slide", background_color: 'blue' do
105
+ slide "A slide", background: 'blue' do
106
106
  #…
107
107
  end
108
108
  end
109
109
  ```
110
110
 
111
+ The `background` option also supports images. If you give a the name of a
112
+ image, it will look for a file by that name in your `images` directory.
113
+
114
+ ```ruby
115
+ presentation "My Presentation" do
116
+ slide "A slide", background: 'bunnies.gif' do
117
+ #…
118
+ end
119
+ end
120
+ ```
121
+
122
+ You can also give it a url to load a remote image.
123
+
124
+ ```ruby
125
+ presentation "My Presentation" do
126
+ slide "A slide", background: 'http://example.com/bunnies.gif' do
127
+ #…
128
+ end
129
+ end
130
+ ```
111
131
 
112
132
  **defaults**
113
133
 
@@ -1,6 +1,7 @@
1
1
  require_relative "slide_hero/version"
2
2
  require_relative "slide_hero/plugins"
3
- require_relative "slide_hero/slide"
3
+ require_relative "slide_hero/compilable"
4
+ require_relative "slide_hero/pluggable"
4
5
  require_relative "slide_hero/point"
5
6
  require_relative "slide_hero/list"
6
7
  require_relative "slide_hero/list_point"
@@ -11,6 +12,7 @@ require_relative "slide_hero/note"
11
12
  require_relative "slide_hero/image"
12
13
  require_relative "slide_hero/remote_image"
13
14
  require_relative "slide_hero/media"
15
+ require_relative "slide_hero/slide"
14
16
  require_relative "slide_hero/dsl"
15
17
 
16
18
  module SlideHero
@@ -1,18 +1,13 @@
1
1
  module SlideHero
2
2
  class Code
3
+ include Compilable
3
4
  attr_reader :language, :source, :location
4
5
  def initialize(language, code_path=Dir.pwd, &code_file)
5
6
  @language = language
6
7
  @location = "#{code_path}/code/#{code_file.call}"
7
8
  @source = File.read(location)
8
- rescue Errno::ENOENT
9
+ rescue Errno::ENOENT
9
10
  abort "#{Dir.pwd}/#{code_file.call} not found"
10
11
  end
11
-
12
- def compile
13
- Tilt::ERBTemplate.
14
- new(File.join(SlideHero.template_path,
15
- 'lib/slide_hero/views/code.html.erb')).render(self)
16
- end
17
12
  end
18
13
  end
@@ -0,0 +1,22 @@
1
+ module SlideHero
2
+ module Compilable
3
+ def compile
4
+ Tilt::ERBTemplate.new(
5
+ File.join(SlideHero.template_path, template)).render(self).strip
6
+ end
7
+
8
+ def template
9
+ template_file = underscore(self.class.name.split("::").last)
10
+ "lib/slide_hero/views/#{template_file}.html.erb"
11
+ end
12
+
13
+ def underscore(camel_cased_word)
14
+ return camel_cased_word unless camel_cased_word =~ /[A-Z-]|::/
15
+ word = camel_cased_word.to_s.gsub(/::/, '/')
16
+ word.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2')
17
+ word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
18
+ word.downcase!
19
+ word
20
+ end
21
+ end
22
+ end
@@ -1,16 +1,11 @@
1
1
  module SlideHero
2
2
  class GroupedSlides
3
+ include Compilable
3
4
  def initialize(slide_defaults={}, &block)
4
5
  @slide_defaults = slide_defaults
5
6
  instance_eval(&block)
6
7
  end
7
8
 
8
- def compile
9
- Tilt::ERBTemplate.
10
- new(File.join(SlideHero.template_path,
11
- 'lib/slide_hero/views/grouped_slides.html.erb')).render(self)
12
- end
13
-
14
9
  def slide(headline, **kwargs, &block)
15
10
  slides << Slide.new(headline, @slide_defaults.merge(**kwargs), &block).compile
16
11
  end
@@ -1,5 +1,6 @@
1
1
  module SlideHero
2
2
  class Image
3
+ include Compilable
3
4
  attr_reader :location, :alt_text, :width, :height
4
5
  def initialize(location, alt_text="", width:nil, height:nil)
5
6
  @location = location
@@ -8,10 +9,6 @@ module SlideHero
8
9
  @height = height
9
10
  end
10
11
 
11
- def compile
12
- %{<img#{width_attribute}#{height_attribute} src="images/#{location}" alt="#{alt_text}">}
13
- end
14
-
15
12
  def height_attribute
16
13
  %{ height="#{height}"} if height
17
14
  end
@@ -3,17 +3,19 @@ module SlideHero
3
3
  attr_reader :style
4
4
 
5
5
  def initialize(style=:unordered, &block)
6
- @style = style
6
+ @style = style
7
7
  instance_eval(&block)
8
8
  end
9
9
 
10
10
  def compile
11
11
  if style == :unordered
12
- Tilt::ERBTemplate.new(File.join(SlideHero.template_path,
13
- 'lib/slide_hero/views/unordered_list.html.erb')).render(self)
12
+ Tilt::ERBTemplate.new(
13
+ File.join(SlideHero.template_path, 'lib/slide_hero/views/unordered_list.html.erb')).
14
+ render(self).strip
14
15
  else
15
- Tilt::ERBTemplate.new(File.join(SlideHero.template_path,
16
- 'lib/slide_hero/views/ordered_list.html.erb')).render(self)
16
+ Tilt::ERBTemplate.new(
17
+ File.join(SlideHero.template_path, 'lib/slide_hero/views/ordered_list.html.erb')).
18
+ render(self).strip
17
19
  end
18
20
  end
19
21
 
@@ -1,7 +1,9 @@
1
1
  module SlideHero
2
2
  class ListPoint
3
+ include Compilable
4
+ alias_method :to_s, :compile
3
5
  attr_reader :animation, :text
4
- SUPPORTED_ANIMATIONS = %w{grow shrink roll-in fade-out
6
+ SUPPORTED_ANIMATIONS = %w{grow shrink roll-in fade-out
5
7
  highlight-red highlight-green highlight-blue}
6
8
 
7
9
  def initialize(text, options={})
@@ -9,15 +11,11 @@ module SlideHero
9
11
  @animation = options[:animation]
10
12
  end
11
13
 
12
- def to_s
13
- "<li#{animation_class}>#{text}</li>"
14
- end
15
-
16
14
  def animation_class
17
15
  if animation
18
- animation_markup = ' class="fragment '
16
+ animation_markup = ' class="fragment '
19
17
  if SUPPORTED_ANIMATIONS.include? animation
20
- animation_markup << animation
18
+ animation_markup << animation
21
19
  end
22
20
  animation_markup + "\""
23
21
  end
@@ -1,13 +1,10 @@
1
1
  module SlideHero
2
2
  class Media
3
+ include Compilable
3
4
  attr_reader :url, :type
4
5
  def initialize(url, type: :video)
5
6
  @url = url
6
7
  @type = type
7
8
  end
8
-
9
- def compile
10
- %{<#{type} data-autoplay src="#{type}/#{url}"></#{type}>}
11
- end
12
9
  end
13
10
  end
@@ -1,12 +1,9 @@
1
1
  module SlideHero
2
2
  class Note
3
+ include Compilable
3
4
  attr_reader :text
4
5
  def initialize(text)
5
6
  @text = text
6
7
  end
7
-
8
- def compile
9
- %{<aside class="notes">#{text}</aside>}
10
- end
11
8
  end
12
9
  end
@@ -0,0 +1,31 @@
1
+ module SlideHero
2
+ module Pluggable
3
+ def create_plugs_for(*klasses)
4
+ klasses.each do |klass|
5
+ method_name = class_name_to_method_name(klass.name)
6
+ fields = initialization_fields_from_class(klass)
7
+
8
+ module_eval %{
9
+ def #{method_name}(#{fields})
10
+ points << #{klass}.new(#{fields}).compile
11
+ end
12
+ }
13
+ end
14
+ end
15
+
16
+ def class_name_to_method_name(class_name)
17
+ class_name.split("::")[-1].
18
+ gsub(/([A-Z]\w*)([A-Z]\w*)/, '\1_\2').
19
+ downcase
20
+ end
21
+
22
+ def initialization_fields_from_class(klass)
23
+ fields = ""
24
+ arguments = klass.instance_method(:initialize).parameters.to_h
25
+ fields << "*args" if arguments.has_key?(:req) || arguments.has_key?(:opt)
26
+ fields << ", **kwargs" if arguments.has_key?(:key)
27
+ fields << ", &block" if arguments.has_key?(:block)
28
+ fields
29
+ end
30
+ end
31
+ end
@@ -1,7 +1,8 @@
1
1
  module SlideHero
2
2
  class Point
3
+ include Compilable
3
4
  attr_reader :text
4
- SUPPORTED_ANIMATIONS = %w{grow shrink roll-in fade-out
5
+ SUPPORTED_ANIMATIONS = %w{grow shrink roll-in fade-out
5
6
  highlight-red highlight-green highlight-blue}
6
7
 
7
8
  def initialize(text, animation: nil)
@@ -9,16 +10,12 @@ module SlideHero
9
10
  @animation = animation
10
11
  end
11
12
 
12
- def compile
13
- "<p#{animation}>#{text}</p>"
14
- end
15
-
16
13
  private
17
14
  def animation
18
15
  if @animation
19
- animation_markup = ' class="fragment '
16
+ animation_markup = ' class="fragment '
20
17
  if SUPPORTED_ANIMATIONS.include? @animation
21
- animation_markup << @animation
18
+ animation_markup << @animation
22
19
  end
23
20
  animation_markup + "\""
24
21
  end
@@ -1,53 +1,24 @@
1
1
  module SlideHero
2
2
  class Slide
3
- attr_reader :headline, :headline_size, :transition, :background_color
4
- def initialize(headline=nil, headline_size: :medium, transition: :default, background_color: nil, &point_block)
3
+ include Compilable
4
+ extend Pluggable
5
+
6
+ attr_reader :headline, :headline_size, :transition, :background
7
+ def initialize(headline=nil, headline_size: :medium, transition: :default, background: nil, &point_block)
5
8
  @headline = headline
6
9
  @headline_size = headline_size
7
10
  @transition = transition
8
11
 
9
- @background_color = background_color
12
+ @background= background
10
13
  instance_eval(&point_block) if block_given?
11
14
  end
12
15
 
13
- def compile
14
- Tilt::ERBTemplate.new(File.join(SlideHero.template_path,
15
- 'lib/slide_hero/views/slide.html.erb')).
16
- render(self)
17
- end
18
-
19
- def point(text, animation: nil)
20
- points << Point.new(text, animation: animation).compile
21
- end
22
-
23
- def list(style=:unordered, &block)
24
- points << List.new(style, &block).compile
25
- end
26
-
27
- def code(*args, &code)
28
- points << Code.new(*args, &code).compile
29
- end
16
+ create_plugs_for Note, Point, List, Code, Image, RemoteImage, Media
30
17
 
31
18
  def points
32
19
  @points ||= []
33
20
  end
34
21
 
35
- def note(text)
36
- points << Note.new(text).compile
37
- end
38
-
39
- def image(*args, **kwargs)
40
- points << Image.new(*args, **kwargs).compile
41
- end
42
-
43
- def remote_image(*args, **kwargs)
44
- points << RemoteImage.new(*args, **kwargs).compile
45
- end
46
-
47
- def media(*args, **kwargs)
48
- points << Media.new(*args, **kwargs).compile
49
- end
50
-
51
22
  private
52
23
  def size_to_markup
53
24
  {
@@ -59,8 +30,14 @@ module SlideHero
59
30
 
60
31
  def data_attributes
61
32
  "data-transition=\"#{transition}\"".tap do |attr|
62
- if background_color
63
- attr << " data-background=\"#{background_color}\""
33
+ case
34
+ when String(background).start_with?('http')
35
+ attr << " data-background=\"#{background}\""
36
+ when String(background).include?('.')
37
+ filename = background.gsub(/\s/, "%20")
38
+ attr << " data-background=\"/images/#{filename}\""
39
+ when background
40
+ attr << " data-background=\"#{background}\""
64
41
  end
65
42
  end
66
43
  end
@@ -1,3 +1,3 @@
1
1
  module SlideHero
2
- VERSION = "0.0.9"
2
+ VERSION = "0.0.10"
3
3
  end
@@ -0,0 +1 @@
1
+ <img<%= width_attribute %><%= height_attribute %> class="stretch" src="images/<%= location %>" alt="<%= alt_text %>">
@@ -0,0 +1 @@
1
+ <li<%= animation_class %>><%= text %></li>
@@ -0,0 +1 @@
1
+ <<%= type %> data-autoplay src="<%= type %>/<%= url %>"></<%= type %>>
@@ -0,0 +1 @@
1
+ <aside class="notes"><%= text %></aside>
@@ -0,0 +1 @@
1
+ <p<%= animation %>><%= text %></p>
@@ -4,12 +4,12 @@ module SlideHero
4
4
  describe Image do
5
5
  it "takes an image path and renders appropriate markup" do
6
6
  image = Image.new("cornify.gif", "Unicorn", width: 280, height: 326)
7
- image.compile.must_equal %{<img width="280" height="326" src="images/cornify.gif" alt="Unicorn">}
7
+ image.compile.must_equal %{<img width="280" height="326" class="stretch" src="images/cornify.gif" alt="Unicorn">}
8
8
  end
9
9
 
10
10
  it "doesn't require all fields" do
11
11
  image = Image.new("cornify.gif")
12
- image.compile.must_equal %{<img src="images/cornify.gif" alt="">}
12
+ image.compile.must_equal %{<img class="stretch" src="images/cornify.gif" alt="">}
13
13
  end
14
14
  end
15
15
  end
@@ -17,7 +17,7 @@ module SlideHero
17
17
 
18
18
  destination_folder = File.join(Dir.pwd,"test","tmp","images")
19
19
  image = RemoteImage.new("http://example.com/troll.png", "Troll", width: 280, height: 326, as: "le_troll", destination: destination_folder)
20
- image.compile.must_equal %{<img width="280" height="326" src="images/le_troll.png" alt="Troll">}
20
+ image.compile.must_equal %{<img width="280" height="326" class="stretch" src="images/le_troll.png" alt="Troll">}
21
21
  assert_requested :get, "http://example.com/troll.png"
22
22
  end
23
23
 
@@ -28,7 +28,7 @@ module SlideHero
28
28
  stub_request(:get, "http://example.com/troll.png")
29
29
 
30
30
  image = RemoteImage.new("http://example.com/troll.png", "Troll", width: 280, height: 326, as: "le_troll", destination: destination_folder)
31
- image.compile.must_equal %{<img width="280" height="326" src="images/le_troll.png" alt="Troll">}
31
+ image.compile.must_equal %{<img width="280" height="326" class="stretch" src="images/le_troll.png" alt="Troll">}
32
32
  assert_not_requested :get, "http://example.com/troll.png"
33
33
  end
34
34
  end
@@ -45,7 +45,7 @@ module SlideHero
45
45
 
46
46
  destination_folder = File.join(Dir.pwd,"test","tmp","images")
47
47
  image = RemoteImage.new("http://example.com/troll.png", "Troll", width: 280, height: 326, destination: destination_folder)
48
- image.compile.must_equal %{<img width="280" height="326" src="images/troll.png" alt="Troll">}
48
+ image.compile.must_equal %{<img width="280" height="326" class="stretch" src="images/troll.png" alt="Troll">}
49
49
  end
50
50
  end
51
51
  end
@@ -23,8 +23,8 @@ module SlideHero
23
23
  end
24
24
 
25
25
  it "can take a background color" do
26
- slide = Slide.new("Badgers learn knitting", background_color: 'blue')
27
- slide.background_color.must_equal 'blue'
26
+ slide = Slide.new("Badgers learn knitting", background: 'blue')
27
+ slide.background.must_equal 'blue'
28
28
  end
29
29
  end
30
30
 
@@ -52,13 +52,39 @@ module SlideHero
52
52
  end
53
53
 
54
54
  it "takes a background_color" do
55
- slide = Slide.new("background_color", background_color: 'blue') do
55
+ slide = Slide.new("background_color", background: 'blue') do
56
56
  end
57
57
  assert_dom_match slide.compile, '<section data-transition="default" ' +
58
58
  'data-background="blue">' +
59
59
  '<h2>background_color</h2>' +
60
60
  '</section>'
61
61
  end
62
+
63
+ it "takes a local image as a background" do
64
+ slide = Slide.new("background image", background: 'lizard.png') do
65
+ end
66
+ assert_dom_match slide.compile, '<section data-transition="default" ' +
67
+ 'data-background="/images/lizard.png">' +
68
+ '<h2>background image</h2>' +
69
+ '</section>'
70
+ end
71
+ it "escapes filenames with spaces" do
72
+ slide = Slide.new("background image", background: 'a lizard.png') do
73
+ end
74
+ assert_dom_match slide.compile, '<section data-transition="default" ' +
75
+ 'data-background="/images/a%20lizard.png">' +
76
+ '<h2>background image</h2>' +
77
+ '</section>'
78
+ end
79
+
80
+ it "can load remote images" do
81
+ slide = Slide.new("remote image", background: 'http://media3.giphy.com/media/ZFlW5pAMdPjJm/200.gif') do
82
+ end
83
+ assert_dom_match slide.compile, '<section data-transition="default" ' +
84
+ 'data-background="http://media3.giphy.com/media/ZFlW5pAMdPjJm/200.gif">' +
85
+ '<h2>remote image</h2>' +
86
+ '</section>'
87
+ end
62
88
  end
63
89
 
64
90
  describe "#point syntax" do
@@ -182,7 +208,7 @@ end
182
208
  image("cornify.gif", "Unicorn", width: 280, height: 326)
183
209
  end
184
210
 
185
- slide.compile.must_include %{<img width="280" height="326" src="images/cornify.gif" alt="Unicorn">}
211
+ slide.compile.must_include %{<img width="280" height="326" class="stretch" src="images/cornify.gif" alt="Unicorn">}
186
212
  end
187
213
  end
188
214
 
@@ -202,7 +228,7 @@ end
202
228
  remote_image("http://example.com/troll.png", "Troll", width: 280, height: 326, as: "le_troll", destination: destination_folder)
203
229
  end
204
230
 
205
- slide.compile.must_include %{<img width="280" height="326" src="images/le_troll.png" alt="Troll">}
231
+ slide.compile.must_include %{<img width="280" height="326" class="stretch" src="images/le_troll.png" alt="Troll">}
206
232
  end
207
233
  end
208
234
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slide_hero
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Nunez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-04 00:00:00.000000000 Z
11
+ date: 2015-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tilt
@@ -143,6 +143,7 @@ files:
143
143
  - bin/slidehero
144
144
  - lib/slide_hero.rb
145
145
  - lib/slide_hero/code.rb
146
+ - lib/slide_hero/compilable.rb
146
147
  - lib/slide_hero/dsl.rb
147
148
  - lib/slide_hero/grouped_slides.rb
148
149
  - lib/slide_hero/image.rb
@@ -150,6 +151,7 @@ files:
150
151
  - lib/slide_hero/list_point.rb
151
152
  - lib/slide_hero/media.rb
152
153
  - lib/slide_hero/note.rb
154
+ - lib/slide_hero/pluggable.rb
153
155
  - lib/slide_hero/plugins.rb
154
156
  - lib/slide_hero/point.rb
155
157
  - lib/slide_hero/presentation.rb
@@ -161,8 +163,13 @@ files:
161
163
  - lib/slide_hero/views/code.html.erb
162
164
  - lib/slide_hero/views/empty.html
163
165
  - lib/slide_hero/views/grouped_slides.html.erb
166
+ - lib/slide_hero/views/image.html.erb
164
167
  - lib/slide_hero/views/layout.html.erb
168
+ - lib/slide_hero/views/list_point.html.erb
169
+ - lib/slide_hero/views/media.html.erb
170
+ - lib/slide_hero/views/note.html.erb
165
171
  - lib/slide_hero/views/ordered_list.html.erb
172
+ - lib/slide_hero/views/point.html.erb
166
173
  - lib/slide_hero/views/slide.html.erb
167
174
  - lib/slide_hero/views/unordered_list.html.erb
168
175
  - slide_hero.gemspec