class Gumdrop::Content

All content (layouts, partials, images, html, js css, etc) found in the source directory are represented as a Content object in memory

Constants

KNOWN_BINARY

Attributes

params[R]
source_path[R]

Public Class Methods

new(source_path, generator=nil, &block) click to toggle source
# File lib/gumdrop/content.rb, line 13
def initialize(source_path, generator=nil, &block)
  @source_path= source_path
  @generator= generator
  @ignore= false
  @block= block
  @params= Util::HashObject.new
end

Private Class Methods

path_match?(path, pattern) click to toggle source
# File lib/gumdrop/content.rb, line 187
def self.path_match?(path, pattern)
   File.fnmatch pattern, path, File::FNM_PATHNAME | File::FNM_DOTMATCH | File::FNM_CASEFOLD
end

Public Instance Methods

binary?() click to toggle source
# File lib/gumdrop/content.rb, line 74
def binary?
  @is_binary ||= begin
    if generated? or has_block? or missing?
      false
    elsif KNOWN_BINARY.include? ext or site.unrenderable? path
      true
    else
      # from ptools
      s = (File.read(source_path, File.stat(source_path).blksize) || "").split(//)
      ((s.size - s.grep(" ".."~").size) / s.size.to_f) > 0.30
    end
  end
end
body() click to toggle source
# File lib/gumdrop/content.rb, line 117
def body # Memoize this?
  @body ||= case
    when has_block?
      @block.call
    when missing?, binary?
      nil
    else
      File.read @source_path
    end
end
clean_uri() click to toggle source
# File lib/gumdrop/content.rb, line 70
def clean_uri
  @clean_uri ||= uri.gsub(ext, '')
end
dirname() click to toggle source
# File lib/gumdrop/content.rb, line 50
def dirname
  @dirname ||= File.dirname source_path
end
exists?() click to toggle source

Can I call body() ?

# File lib/gumdrop/content.rb, line 89
def exists?
  has_block? or File.exists? @source_path
end
ext() click to toggle source
# File lib/gumdrop/content.rb, line 58
def ext
  @ext ||= File.extname filename
end
filename() click to toggle source
# File lib/gumdrop/content.rb, line 46
def filename
  @filename ||= _target_filename
end
generated?() click to toggle source
# File lib/gumdrop/content.rb, line 97
def generated?
  !@generator.nil?
end
generator?() click to toggle source
# File lib/gumdrop/content.rb, line 113
def generator?
  ext == '.generator'
end
has_block?() click to toggle source
# File lib/gumdrop/content.rb, line 101
def has_block?
  !@block.nil?
end
layout?() click to toggle source
# File lib/gumdrop/content.rb, line 109
def layout?
  ext == '.layout'
end
level() click to toggle source
# File lib/gumdrop/content.rb, line 38
def level
  @level ||= (path.split('/').length - 1)
end
method_missing(sym, *args, &block) click to toggle source
Calls superclass method
# File lib/gumdrop/content.rb, line 140
def method_missing(sym, *args, &block)
  if params.has_key? sym
    params[sym]
  else
    super
  end
end
missing?() click to toggle source
# File lib/gumdrop/content.rb, line 93
def missing?
  !exists?
end
mtime() click to toggle source
# File lib/gumdrop/content.rb, line 128
def mtime
  @mtime ||= if exists? and !generated?
      File.mtime @source_path
    else
      Time.now
    end
end
params=(value={}) click to toggle source

TODO: Use a Pathname for all path operations instead of File.*

Add support for relative_to and relative_from to 
ContentList (find?)
# File lib/gumdrop/content.rb, line 25
def params=(value={})
  @params.merge! value
end
partial?() click to toggle source
# File lib/gumdrop/content.rb, line 105
def partial?
  source_filename[0] == "_"
end
path() click to toggle source
# File lib/gumdrop/content.rb, line 34
def path
  @path ||= _source_path
end
slug() click to toggle source
# File lib/gumdrop/content.rb, line 29
def slug
  @slug ||= uri.gsub('/', '-').gsub(ext, '')
  @params.slug || @slug
end
source_filename() click to toggle source
# File lib/gumdrop/content.rb, line 42
def source_filename
  @source_filename ||= File.basename source_path
end
to_s() click to toggle source
# File lib/gumdrop/content.rb, line 136
def to_s
  uri
end
type() click to toggle source
# File lib/gumdrop/content.rb, line 54
def type
  @type ||= File.extname source_filename
end
uri() click to toggle source
# File lib/gumdrop/content.rb, line 62
def uri
  @uri ||= _uri
end
uripath() click to toggle source
# File lib/gumdrop/content.rb, line 66
def uripath
  @uripath ||= File.dirname uri
end

Private Instance Methods

_source_path() click to toggle source
# File lib/gumdrop/content.rb, line 163
def _source_path
  path= @source_path.gsub site.source_path, ''
  if path[0] == '/'
    path[1..-1] 
  else
    path
  end
end
_target_filename() click to toggle source
# File lib/gumdrop/content.rb, line 172
def _target_filename
  filename_parts= source_filename.split('.')
  ext= filename_parts.pop
  while !Renderer.for(ext).nil?
    ext= filename_parts.pop
  end
  filename_parts << ext # push the last file ext back on there!
  fname= filename_parts.join('.')
  if partial?
    fname[1..-1]
  else
    fname
  end
end
_uri() click to toggle source
# File lib/gumdrop/content.rb, line 150
def _uri
  # Do I need to do anything for windoze here to make sure
  # the slashes are / and not \ ?
  uri=  File.dirname(path) / filename
  if uri.starts_with? './'
    uri[2..-1]
  elsif uri.starts_with? '/'
    uri[1..-1]
  else
    uri
  end
end