class Object

Public Instance Methods

anchor(path) click to toggle source
# File lib/bolt/view.rb, line 13
def anchor(path)
  "#" + path
end
create_path(path) click to toggle source
# File lib/bolt/page.rb, line 43
def create_path(path)
  path = path.split('/')
  if path.count > 1
    path = "#{$config.out}/#{path[0..path.length-2].join('/')}"
    if !File.directory?(path)
      FileUtils.mkdir_p(path)
      puts "Created #{path}"
    end
  end
end
page(path) { || ... } click to toggle source

Writes a file containing whatever is returned from a supplied block Will create directories as required by path

# File lib/bolt/page.rb, line 33
def page(path)
  @current_page = path
  create_path(path)
  
  path = "#{$config.out}/#{path}.html"
  File.open(path, 'w') {|f| f.write yield}
  puts "Created #{path}"
end
render(view, options = {}) click to toggle source

Loads the specified view into instance variable @content which is then inserted into a template

# File lib/bolt/page.rb, line 11
def render(view, options = {})
  raise ArgumentError, "Please specify a view to render" if view.empty?
  
  # We have to use nil? here because options[:template] can be false
  options[:template] = $config_file['primary_template'] if options[:template].nil?
  options[:engine] ||= "haml"

  raise ArgumentError, ":engine cannot be view" if options[:engine] == "view"
  
  require options[:engine_require] || options[:engine]
  
  @content = render_view(view_as_string(view, options[:engine]), options[:engine])
  
  if options[:template]
    return render_view(view_as_string(options[:template]), options[:engine])
  else
    return @content
  end
end
render_haml(haml, locals = {}) click to toggle source

Renders haml string, haml

# File lib/bolt/page.rb, line 74
def render_haml(haml, locals = {})
  if locals != false && locals.empty?
    self.instance_variables.each do |var|
      locals[var.to_s.split("@")[1]] = self.instance_variable_get(var)
    end
    
    locals.merge!($config_file)
  end
  
  Haml::Engine.new(haml).render(Object.new, locals)
end
render_view(view, engine) click to toggle source

Renders view with engine

# File lib/bolt/page.rb, line 69
def render_view(view, engine)
  self.send("render_#{engine}", view)
end
u(path) click to toggle source

view.rb bolt

Created by Ben McRedmond on 2010-01-09. Copyright 2010 Ben McRedmond. All rights reserved.

# File lib/bolt/view.rb, line 9
def u(path)
  path + ".html" 
end
view_as_string(view, engine = "haml") click to toggle source

Opens a view file and attempts to read it into a string

# File lib/bolt/page.rb, line 55
def view_as_string(view, engine = "haml")
  v = ""
  path = "#{$config.base_dir}/#{$config.views}/#{view}"
  
  begin
    File.open(path) {|f| v = f.read}
  rescue Errno::ENOENT
    File.open("#{path}.#{engine}") {|f| v = f.read}
  end
  
  v
end