class Gumdrop::Site

Attributes

active_builder[RW]

hmmm…

active_renderer[RW]

hmmm…

contents[R]
data[R]
generators[R]
last_run[R]
layouts[R]
options[R]
partials[R]
root[R]
sitefile[R]

Public Class Methods

new(sitefile, opts={}) click to toggle source

You shouldn’t call this yourself! Access it via Gumdrop.site

# File lib/gumdrop/site.rb, line 41
def initialize(sitefile, opts={})
  Gumdrop.send :set_current_site, self
  @sitefile= sitefile.expand_path
  @options= Util::HashObject.from opts
  _options_updated!
  @root= File.dirname @sitefile
  @last_run= 0
  @_preparations= []

  @contents= ContentList.new
  @layouts= SpecialContentList.new ".layout"
  @partials= SpecialContentList.new
  @generators= []
  @data= DataManager.new

  clear
end

Public Instance Methods

clear() click to toggle source
# File lib/gumdrop/site.rb, line 65
def clear()
  @contents.clear()
  @layouts.clear()
  @partials.clear()
  @generators.clear()
  @data.clear()

  # @contents= ContentList.new
  # @layouts= SpecialContentList.new ".layout"
  # @partials= SpecialContentList.new
  # @generators= []
  # @data= DataManager.new
  
  @is_scanned= false
  _reset_config!
  _load_sitefile
  self
end
config_did_change() click to toggle source
# File lib/gumdrop/site.rb, line 166
def config_did_change
  Gumdrop.init_logging
end
data_path() click to toggle source
# File lib/gumdrop/site.rb, line 134
def data_path
  @data_path ||= data_dir.expand_path(root)
end
generate() click to toggle source
# File lib/gumdrop/site.rb, line 102
def generate
  _execute_preparations
  _execute_generators
  self
end
ignore_path?(path) click to toggle source
# File lib/gumdrop/site.rb, line 114
def ignore_path?(path)
  config.ignore.any? do |pattern|
    path.path_match? pattern
  end
end
in_blacklist?(path) click to toggle source
# File lib/gumdrop/site.rb, line 108
def in_blacklist?(path)
  blacklist.any? do |pattern|
    path.path_match? pattern
  end
end
options=(opts={}) click to toggle source
# File lib/gumdrop/site.rb, line 59
def options=(opts={})
  @options.merge!(opts)
  _options_updated!
end
output_path() click to toggle source
# File lib/gumdrop/site.rb, line 130
def output_path
  @output_path ||= output_dir.expand_path(root)
end
parent() click to toggle source

Events stop bubbling here.

# File lib/gumdrop/site.rb, line 162
def parent
  nil
end
prepare(&block) click to toggle source
# File lib/gumdrop/site.rb, line 157
def prepare(&block)
  @_preparations << block
end
resolve(path=nil, opts={}) click to toggle source
# File lib/gumdrop/site.rb, line 138
def resolve(path=nil, opts={})
  case 
    when path.is_a?(Content)
      path
    when !path.nil?
      contents.first(path) || partials.first(path)
    when opts[:page]
      contents.first opts[:page]
    when opts[:partial]
      partials.first opts[:partial]
    when opts[:layout]
      layouts.first opts[:layout]
    when opts[:generator]
      generators.first opts[:generator]
    else
      nil
  end
end
scan(force=false) click to toggle source
# File lib/gumdrop/site.rb, line 84
def scan(force=false)
  if !@is_scanned or force
    clear if @is_scanned # ????
    _content_scanner
    @is_scanned= true
    generate
  end
  self
end
scan_only() click to toggle source
# File lib/gumdrop/site.rb, line 94
def scan_only # For testing...
  if !@is_scanned or force
    clear if @is_scanned # ????
    _content_scanner
  end
  self
end
source_path() click to toggle source
# File lib/gumdrop/site.rb, line 126
def source_path
  @source_path ||= source_dir.expand_path(root)
end
unrenderable?(path) click to toggle source
# File lib/gumdrop/site.rb, line 120
def unrenderable?(path)
  config.no_render.any? do |pattern|
    path.path_match? pattern
  end
end

Private Instance Methods

_content_scanner() click to toggle source
# File lib/gumdrop/site.rb, line 195
def _content_scanner
  log.info "Gumdrop v#{ Gumdrop::VERSION } - #{ Time.new }"
  log.debug "(config)"
  log.debug config
  log.debug "(options)"
  log.debug @options
  log.debug "[Scanning: #{source_path}]"
  # Report ignore list
  ignore.each {|p| log.debug "  ignoring: #{p}" }
  # Scan Filesystem
  event_block :scan do
    scanner= Util::Scanner.new(source_path, {}, &method(:_scanner_validator)) 
    scanner.each do |path, rel|
      content= Content.new(path)
      layouts.add content and next if content.layout?
      partials.add content and next if content.partial?
      generators << Generator.new(content) and next if content.generator?
      contents.add content
      log.debug " including: #{ rel }"
    end
    contents.keys.size
  end
  @is_scanned= true
end
_execute_generators() click to toggle source
# File lib/gumdrop/site.rb, line 238
def _execute_generators
  log.debug "[Executing Generators]"
  event_block :generate do
    generators.each do |generator|
      generator.execute()
    end
  end
end
_execute_preparations() click to toggle source
# File lib/gumdrop/site.rb, line 226
def _execute_preparations
  log.debug "[Executing Preparations]"
  dsl= Generator::DSL.new nil
  @_preparations.each do |block|
    if block.arity == 1
      block.call dsl
    else
      dsl.instance_eval &block
    end
  end
end
_load_sitefile() click to toggle source
# File lib/gumdrop/site.rb, line 183
def _load_sitefile
  clear_events
  load sitefile
  data.dir= data_path
rescue Exception => ex
  msg= "There is an error in your Gumdrop file!"
  # $stderr.puts msg
  log.error msg
  log.error ex
  raise ex
end
_options_updated!() click to toggle source
# File lib/gumdrop/site.rb, line 178
def _options_updated!
  config.env= @options.env.to_sym if @options.env
  config.mode= @options.mode.nil? ? :unknown : @options.mode.to_sym
end
_reset_config!() click to toggle source
# File lib/gumdrop/site.rb, line 172
def _reset_config!
  config.clear.merge! DEFAULT_CONFIG
  config.env= @options.env.to_sym if @options.env
  config.mode= @options.mode.nil? ? :unknown : @options.mode.to_sym
end
_scanner_validator(source_path, full_path) click to toggle source
# File lib/gumdrop/site.rb, line 220
def _scanner_validator(source_path, full_path)
  return true if ignore_path? source_path
  # in_blacklist? source_path
  false
end