0
# Merb provides views with convenience methods for links images and other
0
+ # We want all possible matches in the FileSys up to the action name
0
+ # Given: controller_name = "namespace/controller"
0
+ # action_name = "action"
0
+ # If all files are present should generate link/script tags for:
0
+ # namespace/controller.(css|js)
0
+ # namespace/controller/action.(css|js)
0
+ (controller_name / action_name).split("/").each do |path|
0
+ css_path = path + ".css"
0
+ if File.exists? Merb.root / "public" / "stylesheets" / css_path
0
+ html << %{<link rel="stylesheet" type="text/css" href="/stylesheets/#{css_path}" /> }
0
+ js_path = path + ".js"
0
+ if File.exists? Merb.root / "public" / "javascripts" / js_path
0
+ html << %{<script type="text/javascript" language="javascript" src="/javascripts/#{js_path}"></script>}
0
+ #Update the prefix for the next iteration
0
+ #Return the generated HTML
0
# name<~to_s>:: The text of the link.
0
# url<~to_s>:: The URL to link to. Defaults to an empty string.
0
# opts<Hash>:: Additional HTML options for the link.
0
# The require_css method can be used to require any CSS file anywhere in
0
# A method used in the layout of an application to create +<script>+ tags
0
# options<Hash>:: Options to pass to js_include_tag.
0
+ # The name of the bundle the scripts should be combined into.
0
# String:: The JavaScript tag.
0
# # <script src="/javascripts/validation.js" type="text/javascript"></script>
0
def include_required_js(options = {})
0
- return '' if @required_js.nil?
0
- js_include_tag(*(@required_js + [options]))
0
+ return '' if @required_js.nil? || @required_js.empty?
0
+ @required_js.map do |req_js|
0
+ if req_js.last.is_a?(Hash)
0
+ js_include_tag(*(req_js[0..-2] + [options.merge(req_js.last)]))
0
+ js_include_tag(*(req_js + [options]))
0
# A method used in the layout of an application to create +<link>+ tags for
0
# String:: The CSS tag.
0
+ # The name of the bundle the stylesheets should be combined into.
0
+ # The media attribute for the generated link element. Defaults to :all.
0
# # my_action.herb has a call to require_css 'style'
0
# # <link href="/stylesheets/ie-specific.css" media="all" rel="Stylesheet" type="text/css"/>
0
def include_required_css(options = {})
0
- return '' if @required_css.nil?
0
- css_include_tag(*(@required_css + [options]))
0
+ return '' if @required_css.nil? || @required_css.empty?
0
+ @required_css.map do |req_css|
0
+ if req_css.last.is_a?(Hash)
0
+ css_include_tag(*(req_css[0..-2] + [options.merge(req_css.last)]))
0
+ css_include_tag(*(req_css + [options]))