Module: WebResourceBundler::RailsAppHelpers

Defined in:
lib/web_resource_bundler/rails_app_helpers.rb

Instance Method Summary collapse

Instance Method Details

#construct_block(block_data, settings) ⇒ Object



23
24
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
# File 'lib/web_resource_bundler/rails_app_helpers.rb', line 23

def construct_block(block_data, settings)
  result = ""
  #we should include only mhtml files if browser IE 7 or 6
  if mhtml_should_be_added?
    styles = block_data.files.select do |f| 
      !([WebResourceBundler::ResourceFileType::MHTML, WebResourceBundler::ResourceFileType::IE_CSS] & f.types).empty?
    end
  else
  #it normal browser - so just including base64 css
    styles = block_data.files.select {|f| f.types.include?(WebResourceBundler::ResourceFileType::CSS)}
  end
  styles.each do |file|
    url = File.join('/', file.path)
    result << stylesheet_link_tag(url) 
    result << "\n"
  end
  block_data.scripts.each do |file|
    url = File.join('/', file.path)
    result << javascript_include_tag(url) 
    result << "\n"
  end
  result << block_data.inline_block unless block_data.inline_block.blank?
  block_data.child_blocks.each do |block|
    result << construct_block(block, settings)
  end
  unless block_data.condition.empty?
    result = "<!--#{block_data.condition}>\n #{result}<![endif]-->\n"
  end
  #removing unnecessary new line symbols
  result.gsub!(/\n(\s)+/, "\n")
  result
end

#mhtml_should_be_added?Boolean

Returns:

  • (Boolean)


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

def mhtml_should_be_added?
  result = false
  pattern = /MSIE (.*?);/
  header = request.headers['HTTP_USER_AGENT']
  match = pattern.match(header)
  if match and match[1] <= '7.0'  
      result = true
  end
  return result
end

#web_resource_bundler_process(&block) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/web_resource_bundler/rails_app_helpers.rb', line 3

def web_resource_bundler_process(&block)
  #getting ActionView::NonConcattingString
  #but we want simple string to escape problems
  result = String.new(capture(&block))
  #result is original block content by default
  version = Rails::VERSION::STRING
  if !params['no_bundler'] and WebResourceBundler::Bundler.instance.settings_correct
    #we want to keep original string unchanged so we can return same content on error
    block_data = WebResourceBundler::Bundler.instance.process(result.dup, request.host_with_port, request.protocol.gsub(/:\/\//,''))
    #if everything ok with bundling we should construct resulted html content and change result
    result = construct_block(block_data, WebResourceBundler::Bundler.instance.settings) if block_data 
  end
  case
    when version >= '3.0.0' then return raw(result) 
    when (version >= '2.2.0' and version < '2.4.0') then concat(result)
  else
    concat(result, block.binding)
  end
end