Module: Gopher::DSL
- Defined in:
- lib/gopher2000/dsl.rb
Overview
DSL that can be used to specify gopher apps with a very simple format.
Instance Method Summary collapse
-
#application ⇒ Gopher::Application
initialize an instance of an Application if we haven't already, otherwise, return the current app.
-
#default_route(&block) ⇒ Object
specify a default route.
-
#helpers { ... } ⇒ Object
specify some helpers for your app.
-
#menu(name) { ... } ⇒ Object
specify a menu template.
-
#mount(path, opts = {}) ⇒ Object
mount a folder for browsing.
-
#route(path) { ... } ⇒ Object
specify a route.
-
#run(script, opts = {}) ⇒ Object
run a script with the specified options applied to the config.
-
#set(key, value = nil) ⇒ Object
set a config value.
-
#text(name) { ... } ⇒ Object
specify a text template.
-
#watch(f) ⇒ Object
watch the specified script for changes.
Instance Method Details
#application ⇒ Gopher::Application
initialize an instance of an Application if we haven't already, otherwise, return
the current app
16 17 18 19 20 21 |
# File 'lib/gopher2000/dsl.rb', line 16 def application return @application unless @application.nil? @application = Gopher::Application.new @application.reset! end |
#default_route(&block) ⇒ Object
specify a default route
38 39 40 |
# File 'lib/gopher2000/dsl.rb', line 38 def default_route(&block) application.default_route(&block) end |
#helpers { ... } ⇒ Object
specify some helpers for your app
79 80 81 |
# File 'lib/gopher2000/dsl.rb', line 79 def helpers(&block) application.helpers(&block) end |
#menu(name) { ... } ⇒ Object
specify a menu template
62 63 64 |
# File 'lib/gopher2000/dsl.rb', line 62 def (name, &block) application.(name, &block) end |
#mount(path, opts = {}) ⇒ Object
mount a folder for browsing
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# 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) { ... } ⇒ Object
specify a route
33 34 35 |
# File 'lib/gopher2000/dsl.rb', line 33 def route(path, &block) application.route(path, &block) end |
#run(script, opts = {}) ⇒ Object
run a script with the specified options applied to the config. This is
called by bin/gopher2000
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# 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) ⇒ Object
set a config value
26 27 28 |
# File 'lib/gopher2000/dsl.rb', line 26 def set(key, value = nil) application.config[key] = value end |
#text(name) { ... } ⇒ Object
specify a text template
69 70 71 |
# File 'lib/gopher2000/dsl.rb', line 69 def text(name, &block) application.text(name, &block) end |
#watch(f) ⇒ Object
watch the specified script for changes
85 86 87 |
# File 'lib/gopher2000/dsl.rb', line 85 def watch(f) application.scripts << f end |