Module: SC::Helpers::StaticHelper
- Included in:
- Builder::Html
- Defined in:
- lib/sproutcore/helpers/static_helper.rb
Instance Method Summary collapse
-
#javascripts_for_client(target_name = nil, opts = {}) ⇒ Object
This method will return the HTML to link to all the javascripts required by the client.
-
#loc(string, opts = {}) ⇒ Object
Localizes the passed string, using the optional passed options.
-
#sc_resource(resource_name, opts = nil) ⇒ Object
Allows you to specify HTML resource this html template should be merged into.
-
#sc_static(resource_name, opts = {}) ⇒ Object
(also: #static_url)
Returns the URL for the named resource.
-
#stylesheets_for_client(target_name = nil, opts = nil) ⇒ Object
This method will return the HTML to link to all the stylesheets required by the named bundle.
-
#theme_name(opts = {}) ⇒ Object
Returns the CSS class name dictated by the current theme.
- #title ⇒ Object
Instance Method Details
#javascripts_for_client(target_name = nil, opts = {}) ⇒ Object
This method will return the HTML to link to all the javascripts required by the client. If you pass no options, the current client will be used.
client_name = the name of the client to render or nil to use the current :language => the language to render. defaults to @language.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/sproutcore/helpers/static_helper.rb', line 78 def javascripts_for_client(target_name = nil, opts = {}) # normalize params if target_name.kind_of?(Hash) && opts.nil? opts = target_name target_name = nil end opts = {} if opts.nil? # process options t = target_name ? target.target_for(target_name) : target # collect urls from entries urls = [] combine_javascript = t.config.combine_javascript combined_entries(t, opts, 'javascript.js', 'javascript-packed.js') do |cur_target, cur_entry| # include either the entry URL or URL of ordered entries # depending on setup if combine_javascript urls << cur_entry.cacheable_url else urls += cur_entry.ordered_entries.map { |e| e.cacheable_url } end # add any stylesheet libs from the target urls += (cur_target.config.javascript_libs || []) end # Convert to HTML and return urls = urls.map do |url| %( <script type="text/javascript" src="#{url}"></script>) end # Add preferred language definition... urls << %(<script type="text/javascript">String.preferredLanguage = "#{language}";</script>) urls.join("\n") end |
#loc(string, opts = {}) ⇒ Object
Localizes the passed string, using the optional passed options.
148 149 150 151 152 |
# File 'lib/sproutcore/helpers/static_helper.rb', line 148 def loc(string, opts = {}) string = string.nil? ? '' : string.to_s language = opts[:language] || self.language return strings_hash(language)[string] || string end |
#sc_resource(resource_name, opts = nil) ⇒ Object
Allows you to specify HTML resource this html template should be merged into. Optionally also specify the layout file to use when building this resource.
Example
<% sc_resource :foo, :layout => 'sproutcore:lib/index.html' %>
141 142 143 144 145 |
# File 'lib/sproutcore/helpers/static_helper.rb', line 141 def sc_resource(resource_name, opts = nil) opts = opts.nil? ? (resource_name.kind_of?(Hash) ? resource_name : {}) : opts @layout = opts[:layout] if opts[:layout] return '' end |
#sc_static(resource_name, opts = {}) ⇒ Object Also known as: static_url
Returns the URL for the named resource
119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/sproutcore/helpers/static_helper.rb', line 119 def sc_static(resource_name, opts = {}) # determine which manifest to search. if a language is explicitly # specified, lookup manifest for that language. otherwise use # current manifest. m = self.manifest if opts[:language] m = target.manifest_for(:language => opts[:language]).build! end entry = m.find_entry(resource_name) entry.nil? ? '' : entry.cacheable_url end |
#stylesheets_for_client(target_name = nil, opts = nil) ⇒ Object
This method will return the HTML to link to all the stylesheets required by the named bundle. If you pass no options, the current client will be used.
bundle_name = the name of the bundle to render or nil to use the current :language => the language to render. defaults to current language
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/sproutcore/helpers/static_helper.rb', line 25 def stylesheets_for_client(target_name = nil, opts = nil) # normalize params if target_name.kind_of?(Hash) && opts.nil? opts = target_name target_name = nil end opts = {} if opts.nil? # process options include_method = opts[:include_method] ||= :link t = target_name ? target.target_for(target_name) : target # collect urls from entries urls = [] combine_stylesheets = t.config.combine_stylesheets combined_entries(t, opts, 'stylesheet.css', 'stylesheet-packed.css') do |cur_target, cur_entry| # include either the entry URL or URL of ordered entries # depending on setup if combine_stylesheets urls << cur_entry.cacheable_url else urls += cur_entry.ordered_entries.map { |e| e.cacheable_url } end # add any stylesheet libs from the target urls += (cur_target.config.stylesheet_libs || []) end # Convert to HTML and return urls = urls.map do |url| if include_method == :import %( @import url('#{url}');) else %( <link href="#{url}" rel="stylesheet" type="text/css" />) end end # if include style is @import, surround with style tags if include_method == :import %(<style type="text/css">\n#{urls * "\n"}</style>) else urls.join("\n") end end |
#theme_name(opts = {}) ⇒ Object
Returns the CSS class name dictated by the current theme. You can also pass an optional default value to use if no theme is specified in the config. The value returned here will use either the theme_name set in the target's config or the theme_name set by the theme framework, if set.
159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/sproutcore/helpers/static_helper.rb', line 159 def theme_name(opts ={}) ret = opts[:default] || 'sc-theme' if target.config.theme_name ret = target.config.theme_name elsif target.config.theme if theme_target = target.target_for(target.config.theme) ret = theme_target.config.theme_name || ret end end return ret end |
#title ⇒ Object
171 172 173 |
# File 'lib/sproutcore/helpers/static_helper.rb', line 171 def title target.config.title || target.target_name.to_s.sub(/^\//,'').gsub(/[-_\/]/,' ').split(' ').map { |x| x.capitalize }.join(' ') end |