Module: Sinatra::RbbtToolHelper

Defined in:
lib/rbbt/rest/web_tool.rb

Instance Method Summary collapse

Instance Method Details

#tool(toolname, options = {}, &block) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rbbt/rest/web_tool.rb', line 4

def tool(toolname, options = {}, &block)
  options[:id] ||= toolname.to_s + "_#{rand(10000)}"

  options[:block] = block if block_given?

  template_file = locate_template("tools/#{toolname}")
  Log.debug "Loading tool #{toolname} from: #{template_file}"
  content = Tilt::HamlTemplate.new(template_file, :filename => template_file).render(self, options)

  styles = begin
             path = locate_sass("tools/#{toolname}")
             link_css "/stylesheets/tools/#{toolname}" if path.exists?
           rescue Exception
             ""
           end

  javascript = begin
                 path = locate_javascript("tools/#{toolname}")
                 link_js "/js-find/tools/#{toolname}" if path.exists?
               rescue Exception
                 ""
               end

  styles + content + javascript
end