Class: Wake::Assets::Renderer
- Inherits:
-
Object
- Object
- Wake::Assets::Renderer
- Defined in:
- lib/wake/assets/renderer.rb
Instance Method Summary collapse
- #include_css(*names) ⇒ Object
- #include_image(*names) ⇒ Object
- #include_js(*names) ⇒ Object
-
#initialize(assets, options) ⇒ Renderer
constructor
A new instance of Renderer.
- #paths_for(type, names, options = {}) ⇒ Object
- #urls_for(type, names, options = {}) ⇒ Object
Constructor Details
#initialize(assets, options) ⇒ Renderer
Returns a new instance of Renderer.
5 6 7 8 9 10 |
# File 'lib/wake/assets/renderer.rb', line 5 def initialize(assets, ) @assets = assets @builds = .fetch(:builds, {}) @hosts = .fetch(:hosts, []) @inline = [:inline] end |
Instance Method Details
#include_css(*names) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/wake/assets/renderer.rb', line 12 def include_css(*names) names, = (names) = if .fetch(:inline, @inline) paths_for(CSS, names, ).map do |path| %Q{#{tag :style, , :type => 'text/css'}#{File.read path}</style>} end else urls_for(CSS, names, ).map do |url| tag :link, , :rel => 'stylesheet', :type => 'text/css', :href => url end end html_safe( * '') end |
#include_image(*names) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/wake/assets/renderer.rb', line 28 def include_image(*names) names, = (names) = if .fetch(:inline, @inline) paths_for(IMG, names, ).map do |path| tag :img, , :src => base64_file(path) end else urls_for(IMG, names, ).map { |url| tag :img, , :src => url } end html_safe( * '') end |
#include_js(*names) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/wake/assets/renderer.rb', line 42 def include_js(*names) names, = (names) = if .fetch(:inline, @inline) paths_for(JS, names, ).map do |path| %Q{#{tag :script, , :type => 'text/javascript'}#{File.read path}</script>} end else urls_for(JS, names, ).map do |url| %Q{#{tag :script, , :type => 'text/javascript', :src => url}</script>} end end html_safe( * '') end |
#paths_for(type, names, options = {}) ⇒ Object
58 59 60 |
# File 'lib/wake/assets/renderer.rb', line 58 def paths_for(type, names, = {}) @assets.paths_for(type, names, {:build => @builds[type]}.merge()) end |
#urls_for(type, names, options = {}) ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/wake/assets/renderer.rb', line 62 def urls_for(type, names, = {}) paths = paths_for(type, names, ).map { |p| @assets.relative(p) } return paths unless @hosts.any? paths.map do |path| @hosts[path.hash % @hosts.size].gsub(/\/*$/, '') + path end end |