Class: Middleman::Presentation::NewSlide
- Inherits:
-
Object
- Object
- Middleman::Presentation::NewSlide
- Includes:
- ComparableSlide
- Defined in:
- lib/middleman-presentation-core/new_slide.rb
Overview
A slide
Instance Method Summary collapse
-
#base_name ⇒ Object
Return basename of slide.
-
#content(**data) ⇒ Object
Generate slide content.
-
#exist? ⇒ Boolean
Does the slide exist.
- #file_name ⇒ Object
- #group ⇒ Object
-
#initialize(input, base_path:) ⇒ NewSlide
constructor
A new instance of NewSlide.
- #path ⇒ Object
-
#relative_path ⇒ Object
Relative path of slide.
-
#to_s ⇒ Object
Return string representation of self.
-
#write(**data) ⇒ Object
Write slide content to file.
Methods included from ComparableSlide
#<=>, #base_name?, #eql?, #group?, #hash, #match?, #similar?
Constructor Details
#initialize(input, base_path:) ⇒ NewSlide
Returns a new instance of NewSlide.
14 15 16 17 18 19 |
# File 'lib/middleman-presentation-core/new_slide.rb', line 14 def initialize(input, base_path:) @input = input.split(/:/) @name = extract_name @slide_directory_path = Pathname.new(base_path) @base_path = @slide_directory_path.dirname end |
Instance Method Details
#base_name ⇒ Object
Return basename of slide
45 46 47 |
# File 'lib/middleman-presentation-core/new_slide.rb', line 45 def base_name File.basename(name).scan(/^([^.]+)(?:\..+)?/).flatten.first end |
#content(**data) ⇒ Object
Generate slide content
It either uses previously set content or generates content by using a predefined template
81 82 83 |
# File 'lib/middleman-presentation-core/new_slide.rb', line 81 def content(**data) Erubis::Eruby.new(template.content).result(data) end |
#exist? ⇒ Boolean
Does the slide exist
73 74 75 |
# File 'lib/middleman-presentation-core/new_slide.rb', line 73 def exist? path.exist? end |
#file_name ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/middleman-presentation-core/new_slide.rb', line 49 def file_name path = if type? :erb Pathname.new "#{base_name}.html.erb" elsif type? :md Pathname.new "#{base_name}.html.md" elsif type? :liquid Pathname.new "#{base_name}.html.liquid" else Pathname.new("#{base_name}.html#{template.proposed_extname}") end Pathname.new(path) end |
#group ⇒ Object
40 41 42 |
# File 'lib/middleman-presentation-core/new_slide.rb', line 40 def group @group ||= extract_group end |
#path ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/middleman-presentation-core/new_slide.rb', line 26 def path p = [] p << Pathname.new(group) unless group.blank? p << file_name # rubocop:disable Style/EachWithObject p.reduce() do |a, e| # rubocop:enable Style/EachWithObject a += e a end end |
#relative_path ⇒ Object
Relative path of slide
86 87 88 |
# File 'lib/middleman-presentation-core/new_slide.rb', line 86 def relative_path path.relative_path_from(base_path) end |
#to_s ⇒ Object
Return string representation of self
22 23 24 |
# File 'lib/middleman-presentation-core/new_slide.rb', line 22 def to_s path.to_s end |
#write(**data) ⇒ Object
Write slide content to file
64 65 66 67 68 69 70 |
# File 'lib/middleman-presentation-core/new_slide.rb', line 64 def write(**data) FileUtils.mkdir_p path.dirname File.open(path, 'wb') do |f| f.write(content(**data)) end end |