Class: Jekyll::LiveSite::ContentFile

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll/live_site.rb

Constant Summary collapse

TYPE_MAPPING =
{
  '_layouts'  => :layout,
  '_includes' => :include,
  '_posts'    => :post
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, source, dest, allowed_checker = nil) ⇒ ContentFile

Returns a new instance of ContentFile.



90
91
92
93
94
95
96
97
98
# File 'lib/jekyll/live_site.rb', line 90

def initialize path, source, dest, allowed_checker = nil
  @path = path
  @source = source
  @destination = dest
  @allowed_checker = allowed_checker || lambda {|f| true }
  @dir, @name = File.split @path
  @type = :file
  @valid_dir = nil
end

Instance Attribute Details

#dirObject (readonly)

Returns the value of attribute dir.



81
82
83
# File 'lib/jekyll/live_site.rb', line 81

def dir
  @dir
end

#nameObject (readonly)

Returns the value of attribute name.



81
82
83
# File 'lib/jekyll/live_site.rb', line 81

def name
  @name
end

#pathObject (readonly) Also known as: to_s

Returns the value of attribute path.



81
82
83
# File 'lib/jekyll/live_site.rb', line 81

def path
  @path
end

Instance Method Details

#deep_checkObject



115
116
117
118
# File 'lib/jekyll/live_site.rb', line 115

def deep_check
  return @valid_dir unless @valid_dir.nil?
  @valid_dir = valid_dir? self.dir
end

#relative_dirObject



105
106
107
# File 'lib/jekyll/live_site.rb', line 105

def relative_dir
  @relative_dir ||= self.dir.sub(File.join(@source, ''), '')
end

#typeObject



100
101
102
103
# File 'lib/jekyll/live_site.rb', line 100

def type
  deep_check
  @type
end

#valid?Boolean

Returns:

  • (Boolean)


109
110
111
112
113
# File 'lib/jekyll/live_site.rb', line 109

def valid?
  !File.symlink? path and
    @allowed_checker.call(name) and
      deep_check
end

#valid_dir?(path) ⇒ Boolean

Returns:

  • (Boolean)


120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/jekyll/live_site.rb', line 120

def valid_dir? path
  if path == '/'
    false
  elsif path == @destination
    false
  elsif path == @source
    true
  elsif File.symlink? path
    false
  else
    dir, name = File.split path
    if type = TYPE_MAPPING[name]
      @type = type
    elsif !@allowed_checker.call(name)
      return false
    end
    valid_dir? dir
  end
end