Class: Middleman::Presentation::ExistingSlide

Inherits:
Object
  • Object
show all
Includes:
ComparableSlide
Defined in:
lib/middleman-presentation-core/existing_slide.rb

Overview

Used for slides which already exist in file system

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ComparableSlide

#<=>, #base_name?, #eql?, #group?, #hash, #match?, #similar?

Constructor Details

#initialize(path, base_path: nil) ⇒ ExistingSlide

Create Existin slide object



17
18
19
20
21
22
# File 'lib/middleman-presentation-core/existing_slide.rb', line 17

def initialize(path, base_path: nil)
  @path      = Pathname.new(path)

  base_path = @path.dirname if base_path.blank?
  @base_path = Pathname.new(base_path)
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



8
9
10
# File 'lib/middleman-presentation-core/existing_slide.rb', line 8

def path
  @path
end

Instance Method Details

#base_nameObject

Return base name for slide



68
69
70
71
72
73
74
# File 'lib/middleman-presentation-core/existing_slide.rb', line 68

def base_name
  base = relative_path.basename

  base = base.basename('.*') until base.extname.blank?

  base.to_s
end

#exist?Boolean

Does slide really exist in filesystem

Returns:

  • (Boolean)


40
41
42
# File 'lib/middleman-presentation-core/existing_slide.rb', line 40

def exist?
  path.exist?
end

#ext_nameObject

Return ext name for slide



77
78
79
# File 'lib/middleman-presentation-core/existing_slide.rb', line 77

def ext_name
  file_name.to_s.gsub(/^([^.]+)\./, '.')
end

#file_nameObject

Filename of slide, e.g 01.html.erb



35
36
37
# File 'lib/middleman-presentation-core/existing_slide.rb', line 35

def file_name
  path.basename
end

#groupObject

Group of slide



30
31
32
# File 'lib/middleman-presentation-core/existing_slide.rb', line 30

def group
  @group ||= extract_group
end

#partial_pathObject

Return partial path of existing slide



59
60
61
62
63
64
65
# File 'lib/middleman-presentation-core/existing_slide.rb', line 59

def partial_path
  dirname, base = relative_path.split

  base = base.basename('.*') until base.extname.blank?

  dirname + base
end

#relative_pathObject

Relative path inside source directory



25
26
27
# File 'lib/middleman-presentation-core/existing_slide.rb', line 25

def relative_path
  path.relative_path_from(base_path)
end

#render(&block) ⇒ Object

Render slide



45
46
47
48
49
50
51
# File 'lib/middleman-presentation-core/existing_slide.rb', line 45

def render(&block)
  result = []
  result << "<!-- #{relative_path} -->"
  result << block.call(path).to_s

  result.join("\n")
end

#to_sObject

String representation of slide



54
55
56
# File 'lib/middleman-presentation-core/existing_slide.rb', line 54

def to_s
  path.to_s
end