Class: Marley::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/marley/jamaica.rb

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Client

Here we define the Jamaica client class for Marley. This client is a simple HTML page that is intended to be run in a browser. It will have its actual UI metadata in the global variable ‘_jamaica_json’ and onDocumentReady, this will be turned into the client UI.



7
8
9
10
11
12
# File 'lib/marley/jamaica.rb', line 7

def initialize(opts={})
  @opts={:app_name => 'Application',:css => '', :js => ''}.merge(opts)
  @client_dir="#{File.dirname(__FILE__)}/client/"
  @libs = Dir.glob("#{@client_dir}*.js").sort
  @styles = [ 'jamaica.css' ]
end

Instance Method Details

#css(add_css = nil) ⇒ Object



19
20
21
22
# File 'lib/marley/jamaica.rb', line 19

def css(add_css=nil)
  @opts[:css]+=add_css if add_css
  @opts[:css]
end

#joint(joint_d, joint_name) ⇒ Object



13
14
15
16
17
18
# File 'lib/marley/jamaica.rb', line 13

def joint(joint_d,joint_name)
  [:css,:js].each do |ext|
    fn="#{joint_d}#{joint_name}.#{ext.to_s}"
    File.exists?(fn) && send(ext,File.new(fn,"r").read)
  end
end

#js(add_js = nil) ⇒ Object



23
24
25
26
# File 'lib/marley/jamaica.rb', line 23

def js(add_js=nil)
  @opts[:js]+=add_js if add_js
  @opts[:js]
end

#to_s(json = '') ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/marley/jamaica.rb', line 27

def to_s(json='')
  <<-EOHTML
  <head>
    <title>#{@opts[:app_name]}</title>
    <script type='text/javascript'>var _jamaica_json=#{json}; #{ @libs.map{ |l| File.new(l).read }.push(@opts[:js]).join("\n") }</script>
    <style>#{ @styles.map{ |s| File.new("#{@client_dir}#{s}").read }.push(@opts[:css]).join("\n") }
  </head>
  <body></body>
  EOHTML
end