module Gopher::DSL

DSL that can be used to specify gopher apps with a very simple format. @see the examples/ directory for working scripts

Public Instance Methods

application() click to toggle source

initialize an instance of an Application if we haven’t already, otherwise, return

the current app

@return [Gopher::Application] current app

# File lib/gopher2000/dsl.rb, line 16
def application
  return @application unless @application.nil?

  @application = Gopher::Application.new
  @application.reset!
end
default_route(&block) click to toggle source

specify a default route

# File lib/gopher2000/dsl.rb, line 38
def default_route(&block)
  application.default_route(&block)
end
helpers(&block) click to toggle source

specify some helpers for your app @yield block which defines the helper methods

# File lib/gopher2000/dsl.rb, line 79
def helpers(&block)
  application.helpers(&block)
end
menu(name, &block) click to toggle source

specify a menu template @param [Symbol] name of the template @yield block which renders the template

mount(path, opts = {}) click to toggle source

mount a folder for browsing

# File lib/gopher2000/dsl.rb, line 43
def mount(path, opts = {})
  route, folder = path.first

  #
  # if path has more than the one option (:route => :folder),
  # then incorporate the rest of the hash into our opts
  #
  if path.size > 1
    other_opts = path.dup
    other_opts.delete(route)
    opts = opts.merge(other_opts)
  end

  application.mount(route, opts.merge({:path => folder}))
end
route(path, &block) click to toggle source

specify a route @param [String] path path of the route @yield block that will respond to the request

# File lib/gopher2000/dsl.rb, line 33
def route(path, &block)
  application.route(path, &block)
end
run(script, opts = {}) click to toggle source

run a script with the specified options applied to the config. This is

called by bin/gopher2000

@param [String] script path to script to run @param [Hash] opts options to pass to script. these will override any

config options specified in the script, so you can use this to
run on a different host/port, etc.
# File lib/gopher2000/dsl.rb, line 97
def run(script, opts = {})

  load script

  #
  # apply options after loading the script so that anything specified on the command-line
  # will take precedence over defaults specified in the script
  #
  opts.each { |k, v|
    set k, v
  }

  if application.config[:debug] == true
    puts "watching #{script} for changes"
    watch script
  end

end
set(key, value = nil) click to toggle source

set a config value @param [Symbol] key key to add to config @param [String] value value to set

# File lib/gopher2000/dsl.rb, line 26
def set(key, value = nil)
  application.config[key] = value
end
text(name, &block) click to toggle source

specify a text template @param [Symbol] name of the template @yield block which renders the template

# File lib/gopher2000/dsl.rb, line 69
def text(name, &block)
  application.text(name, &block)
end
watch(f) click to toggle source

watch the specified script for changes @param [String] f script to watch

# File lib/gopher2000/dsl.rb, line 85
def watch(f)
  application.scripts << f
end