Module: Tarpaulin::Helpers

Defined in:
lib/tarpaulin/camping.rb

Overview

included into TheApp::Helpers module

Constant Summary collapse

IMAGE =

could do all these with a bit of meta-programming

'images'
CSS =

cascading_stylesheets

'cascading_stylesheets'
JS =
'javascripts'
@@empty_hdf =
Neo::Hdf.new

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(mod) ⇒ Object



55
56
57
58
59
# File 'lib/tarpaulin/camping.rb', line 55

def self.included(mod)
  $DEBUG and $stderr.puts "h:mod is #{@mod}"
  @mod = mod
  $DEBUG and $stderr.puts "now it is #{@mod}"
end

Instance Method Details

#css_dirObject



81
82
83
# File 'lib/tarpaulin/camping.rb', line 81

def css_dir
  File.join(document_root, CSS)
end

#document_rootObject

should be configified



62
63
64
65
66
# File 'lib/tarpaulin/camping.rb', line 62

def document_root # or whatever ...
  '/var/www/localhost/htdocs/'
  # /Users/jollyrotten/Code/poetify/y_ruby
  # File.dirname(__FILE__)
end

#hdf_render(*a) ⇒ Object



137
138
139
140
141
# File 'lib/tarpaulin/camping.rb', line 137

def hdf_render *a
  block_given? ?
     render(*a, &Proc.new) :
     render(*a) { @@empty_hdf }
end

#http_hostObject

should be configified



69
70
71
# File 'lib/tarpaulin/camping.rb', line 69

def http_host # or whatever ...
  @env['HTTP_HOST']
end

#image_dirObject



76
77
78
# File 'lib/tarpaulin/camping.rb', line 76

def image_dir
  File.join(document_root, IMAGE)
end


118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/tarpaulin/camping.rb', line 118

def javascript_link_tag(scriptish)
  type = "text/javascript"
  src = if scriptish.start_with?("http") or scriptish.start_with?("//")  # 3rd party css? really?
    "#{scriptish}"
  else
    root = prepare_root
    (root and root.length > 0) ?
      R(link_controller, root, Tarpaulin::Helpers::JS, "#{scriptish}.js") :
      R(link_controller, Tarpaulin::Helpers::JS, "#{scriptish}.js")
  end

  Markaby::Builder.new.capture {
    script(:type => type, :src => src) do
    end
  }
end

#js_dirObject



86
87
88
# File 'lib/tarpaulin/camping.rb', line 86

def js_dir
  File.join(document_root, JS)
end

#prepare_rootObject



90
91
92
93
94
95
96
97
# File 'lib/tarpaulin/camping.rb', line 90

def prepare_root
  if @root.length > 0 and @root[0] == '/'.ord
    root = @root.reverse.chop!.reverse
  else
    root = @root
  end
  root
end


99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/tarpaulin/camping.rb', line 99

def stylesheet_link_tag(stylish)
  type = "text/css"
  href = if stylish.start_with?("http") or stylish.start_with?("//")
    "#{stylish}"
  else
    root = prepare_root
    (root and root.length > 0) ?
      R(link_controller, root, Tarpaulin::Helpers::CSS, "#{stylish}.css") :
      R(link_controller, Tarpaulin::Helpers::CSS, "#{stylish}.css")
  end
  
  Markaby::Builder.new.capture {
    link :rel => "stylesheet",
         :type => type,
         :media => "screen",
         :href => href
  }
end