Class: Apphtml::Helper

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

Constant Summary collapse

@@helperself =
nil

Instance Method Summary collapse

Constructor Details

#initialize(css, js) ⇒ Helper

Returns a new instance of Helper.



43
44
45
46
# File 'lib/apphtml.rb', line 43

def initialize css, js
  @css = css
  @js = js
end

Instance Method Details

#add(pathset, typ) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/apphtml.rb', line 90

def add pathset, typ
  subject = case typ
            when :css then @css
            when :js then @js
            end

  if subject
    subject.each do |pth|
      pathset << pth unless Dir[(dir(typ) % pth)].empty?
    end
  end
  pathset
end

#based_on_params(request_path) ⇒ Object



56
57
58
59
60
61
62
63
64
65
# File 'lib/apphtml.rb', line 56

def based_on_params request_path
  pathset = []
  request_path.split('/').each_with_object("") do |dir,txt|
    unless dir =~ /^\s*$/
      txt << "/#{dir}"
      pathset << txt.dup unless pathset.include?(txt)
    end
  end
  pathset
end

#css_based_on_params(request_path) ⇒ Object



48
49
50
# File 'lib/apphtml.rb', line 48

def css_based_on_params request_path
  add *(to_path(based_on_params(request_path), :css))
end

#dir(typ) ⇒ Object



77
78
79
80
81
82
83
84
# File 'lib/apphtml.rb', line 77

def dir typ
  case
  when :css
    @css_dir ||= %{#{Rails.root}/app/assets/stylesheets/%s.css*}
  when :js
    @js_dir ||= %{#{Rails.root}/app/assets/javascripts/%s.js*}
  end
end

#js_based_on_params(request_path) ⇒ Object



52
53
54
# File 'lib/apphtml.rb', line 52

def js_based_on_params request_path
  add *(to_path(based_on_params(request_path), :js))
end

#js_dirObject



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

def js_dir
  @js_dir ||= %{#{Rails.root}/app/assets/javascripts/%s.js*}
end

#to_path(pathset, typ) ⇒ Object



67
68
69
70
71
72
73
74
75
# File 'lib/apphtml.rb', line 67

def to_path pathset, typ
  resp = pathset.each_with_object([]) do |pth,resp|
    pth.sub!(%r{^/}, '')
    unless Dir[(dir(typ) % pth)].empty?
      resp << pth
    end
  end
  [resp, typ]
end