Module: SecureHeaders::TaskHelper

Includes:
HashHelper
Defined in:
lib/secure_headers/task_helper.rb

Constant Summary collapse

INLINE_SCRIPT_REGEX =
/(<script(\s*(?!src)([\w\-])+=([\"\'])[^\"\']+\4)*\s*>)(.*?)<\/script>/mx
INLINE_STYLE_REGEX =
/(<style[^>]*>)(.*?)<\/style>/mx
INLINE_HASH_SCRIPT_HELPER_REGEX =
/<%=\s?hashed_javascript_tag(.*?)\s+do\s?%>(.*?)<%\s*end\s*%>/mx
INLINE_HASH_STYLE_HELPER_REGEX =
/<%=\s?hashed_style_tag(.*?)\s+do\s?%>(.*?)<%\s*end\s*%>/mx

Instance Method Summary collapse

Methods included from HashHelper

#hash_source

Instance Method Details

#dynamic_content?(filename, inline_script) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
33
34
35
# File 'lib/secure_headers/task_helper.rb', line 30

def dynamic_content?(filename, inline_script)
  !!(
    (is_mustache?(filename) && inline_script =~ /\{\{.*\}\}/) ||
    (is_erb?(filename) && inline_script =~ /<%.*%>/)
    )
end

#generate_inline_script_hashes(filename) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/secure_headers/task_helper.rb', line 12

def generate_inline_script_hashes(filename)
  hashes = []

  hashes.concat find_inline_content(filename, INLINE_SCRIPT_REGEX, false)
  hashes.concat find_inline_content(filename, INLINE_HASH_SCRIPT_HELPER_REGEX, true)

  hashes
end

#generate_inline_style_hashes(filename) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/secure_headers/task_helper.rb', line 21

def generate_inline_style_hashes(filename)
  hashes = []

  hashes.concat find_inline_content(filename, INLINE_STYLE_REGEX, false)
  hashes.concat find_inline_content(filename, INLINE_HASH_STYLE_HELPER_REGEX, true)

  hashes
end