web_resource_bundler 0.0.20 → 0.0.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/lib/web_resource_bundler/content_management/block_data.rb +18 -21
- data/lib/web_resource_bundler/content_management/block_parser.rb +58 -52
- data/lib/web_resource_bundler/content_management/css_url_rewriter.rb +3 -3
- data/lib/web_resource_bundler/content_management/resource_file.rb +38 -25
- data/lib/web_resource_bundler/exceptions.rb +1 -3
- data/lib/web_resource_bundler/file_manager.rb +14 -3
- data/lib/web_resource_bundler/filters/bundle_filter/resource_packager.rb +45 -27
- data/lib/web_resource_bundler/filters/bundle_filter.rb +27 -22
- data/lib/web_resource_bundler/filters/cdn_filter.rb +27 -23
- data/lib/web_resource_bundler/filters/image_encode_filter/css_generator.rb +53 -40
- data/lib/web_resource_bundler/filters/image_encode_filter/image_data.rb +22 -17
- data/lib/web_resource_bundler/filters/image_encode_filter.rb +49 -23
- data/lib/web_resource_bundler/filters.rb +6 -1
- data/lib/web_resource_bundler/rails_app_helpers.rb +56 -40
- data/lib/web_resource_bundler/settings.rb +99 -0
- data/lib/web_resource_bundler/web_resource_bundler_init.rb +1 -1
- data/lib/web_resource_bundler.rb +100 -125
- data/spec/sample_block_helper.rb +3 -3
- data/spec/web_resource_bundler/content_management/block_data_spec.rb +56 -11
- data/spec/web_resource_bundler/content_management/block_parser_spec.rb +24 -10
- data/spec/web_resource_bundler/content_management/resource_file_spec.rb +7 -15
- data/spec/web_resource_bundler/file_manager_spec.rb +12 -4
- data/spec/web_resource_bundler/filters/bundle_filter/filter_spec.rb +5 -5
- data/spec/web_resource_bundler/filters/bundle_filter/resource_packager_spec.rb +15 -2
- data/spec/web_resource_bundler/filters/cdn_filter_spec.rb +15 -7
- data/spec/web_resource_bundler/filters/image_encode_filter/css_generator_spec.rb +44 -4
- data/spec/web_resource_bundler/filters/image_encode_filter/filter_spec.rb +20 -15
- data/spec/web_resource_bundler/settings_spec.rb +77 -0
- data/spec/web_resource_bundler/web_resource_bundler_spec.rb +19 -26
- data/web_resource_bundler.gemspec +4 -4
- metadata +5 -5
- data/lib/web_resource_bundler/settings_manager.rb +0 -91
- data/spec/web_resource_bundler/settings_manager_spec.rb +0 -88
@@ -2,80 +2,93 @@ module WebResourceBundler
|
|
2
2
|
module Filters
|
3
3
|
module ImageEncodeFilter
|
4
4
|
class CssGenerator
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
|
6
|
+
TAGS = %w(background-image background)
|
7
|
+
SEPARATOR = 'A_SEPARATOR'
|
8
|
+
PATTERN = /((#{TAGS.join('|')})\s*:[^\(]*)url\(\s*['|"]([^\)]*)['|"]\s*\)/i
|
9
|
+
MAX_IMAGE_SIZE = 32 #IE 8 limitation
|
10
|
+
MHTML_CONTENT_TYPE = 'Content-Type: multipart/related; boundary="'
|
9
11
|
|
10
12
|
def initialize(settings, file_manager)
|
11
|
-
@settings
|
13
|
+
@settings = settings
|
12
14
|
@file_manager = file_manager
|
13
15
|
end
|
14
16
|
|
15
17
|
def set_settings(settings)
|
16
18
|
@settings = settings
|
17
|
-
@settings[:max_image_size] = MAX_IMAGE_SIZE unless @settings[:max_image_size]
|
18
19
|
end
|
19
20
|
|
20
21
|
#construct mhtml head of css file with definition of image data in base64
|
22
|
+
#each image found in css should be defined in header with base64 encoded content
|
21
23
|
def construct_mhtml_content(images)
|
22
24
|
result = ""
|
23
|
-
|
24
|
-
result <<
|
25
|
-
|
26
|
-
|
27
|
-
result << images[key].construct_mhtml_image_data('--' + SEPARATOR)
|
28
|
-
end
|
29
|
-
result << "\n" << '--' << SEPARATOR << '--' << "\n"
|
25
|
+
if images.any?
|
26
|
+
result << mhtml_header
|
27
|
+
result << mhtml_images_data(images)
|
28
|
+
result << mhtml_footer
|
30
29
|
end
|
31
30
|
result
|
32
31
|
end
|
33
32
|
|
33
|
+
#generates css file for IE with encoded images using mhtml in cache dir
|
34
|
+
#mhtml_filepath - path to file with images encoded in base64
|
35
|
+
#creating new css content with images encoded in base64
|
36
|
+
def encode_images_for_ie!(content, path)
|
37
|
+
encode_images_basic!(content) do |image_data, tag|
|
38
|
+
"#{tag}url(mhtml:#{construct_mhtml_link(path)}!#{image_data.id})"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
#generates css file with encoded images in cache dir
|
43
|
+
def encode_images!(content)
|
44
|
+
encode_images_basic!(content) do |image_data, tag|
|
45
|
+
"#{tag}url('data:image/#{image_data.extension};base64,#{image_data.encoded}')"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def mhtml_header
|
52
|
+
MHTML_CONTENT_TYPE + SEPARATOR + '"' + "\n\n"
|
53
|
+
end
|
54
|
+
|
55
|
+
def mhtml_footer
|
56
|
+
"\n--" + SEPARATOR + "--\n"
|
57
|
+
end
|
58
|
+
|
59
|
+
def mhtml_images_data(images)
|
60
|
+
images.inject("") {|data, i| data << i.construct_mhtml_image_data('--' << SEPARATOR) }
|
61
|
+
end
|
62
|
+
|
34
63
|
#creates mhtml link to use in css tags instead of image url
|
35
64
|
def construct_mhtml_link(filepath)
|
36
65
|
"#{@settings[:protocol]}://#{File.join(@settings[:domain], filepath)}"
|
37
66
|
end
|
38
|
-
|
67
|
+
|
68
|
+
|
39
69
|
#iterates through all tags found in css
|
40
70
|
#if image exist and has proper size - it should be encoded
|
41
|
-
#each tag with this kind of an image is replaced with new one
|
71
|
+
#each tag with this kind of an image is replaced with new one
|
72
|
+
#mhtml link for IE and base64 code for another browser
|
42
73
|
#returns images hash - in case generator can build proper IE css header with base64 images encoded
|
43
74
|
def encode_images_basic!(content)
|
44
75
|
images = {}
|
45
|
-
|
46
|
-
tag
|
47
|
-
|
76
|
+
content.gsub!(PATTERN) do |s|
|
77
|
+
tag = $1
|
78
|
+
url = $3
|
48
79
|
data = ImageData.new(url, @settings[:resource_dir])
|
49
|
-
if !url.empty?
|
50
|
-
#changing string using provided block
|
51
|
-
#using image url as key to prevent one image be encoded many times
|
80
|
+
if !url.empty? && data.exist && data.size <= image_size_limit && block_given?
|
52
81
|
images[url] = data unless images[url]
|
53
|
-
|
82
|
+
yield(images[url], tag)
|
54
83
|
else
|
55
|
-
#returning the same string because user failed with image path - such image non existent
|
56
84
|
s
|
57
85
|
end
|
58
86
|
end
|
59
87
|
images
|
60
88
|
end
|
61
89
|
|
62
|
-
|
63
|
-
|
64
|
-
def encode_images_for_ie!(content, mhtml_filepath)
|
65
|
-
#creating new css content with images encoded in base64
|
66
|
-
images = encode_images_basic!(content) do |image_data, tag|
|
67
|
-
"*#{tag}url(mhtml:#{construct_mhtml_link(mhtml_filepath)}!#{image_data.id})"
|
68
|
-
end
|
69
|
-
images
|
70
|
-
end
|
71
|
-
|
72
|
-
#generates css file with encoded images in cache dir
|
73
|
-
def encode_images!(content)
|
74
|
-
#encoding images in content
|
75
|
-
images = encode_images_basic!(content) do |image_data, tag|
|
76
|
-
"#{tag}url('data:image/#{image_data.extension};base64,#{image_data.encoded}')"
|
77
|
-
end
|
78
|
-
images
|
90
|
+
def image_size_limit
|
91
|
+
@settings[:max_image_size] ? [MAX_IMAGE_SIZE, @settings[:max_image_size]].min : MAX_IMAGE_SIZE
|
79
92
|
end
|
80
93
|
|
81
94
|
end
|
@@ -4,25 +4,21 @@ module WebResourceBundler
|
|
4
4
|
module ImageEncodeFilter
|
5
5
|
#ImageData contains info about image found in css files
|
6
6
|
class ImageData
|
7
|
-
|
7
|
+
|
8
|
+
MHTML_CONTENT_LOCATION = 'Content-Location:'
|
9
|
+
MHTML_CONTENT_ENCODING = 'Content-Transfer-Encoding:base64'
|
10
|
+
|
8
11
|
attr_reader :extension, :id, :path, :exist, :url
|
9
12
|
|
10
13
|
def initialize(url, folder)
|
11
|
-
@url
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
@exist = true
|
16
|
-
else
|
17
|
-
@exist = false
|
18
|
-
end
|
19
|
-
if WebResourceBundler::Bundler.instance.logger and !@path.include?('://') and !@exist
|
20
|
-
WebResourceBundler::Bundler.instance.logger.info("Image not found #{@path}")
|
21
|
-
end
|
14
|
+
@url = url
|
15
|
+
@path = File.join(folder, url)
|
16
|
+
@exist = File.file?(@path)
|
17
|
+
report_problem_if_file_not_found
|
22
18
|
if @exist
|
23
|
-
@size
|
24
|
-
|
25
|
-
@
|
19
|
+
@size = File.size(@path)
|
20
|
+
@id = Digest::MD5.hexdigest(url)
|
21
|
+
@extension = File.basename(@path).split('.').last
|
26
22
|
end
|
27
23
|
end
|
28
24
|
|
@@ -34,8 +30,8 @@ module WebResourceBundler
|
|
34
30
|
def construct_mhtml_image_data(separator)
|
35
31
|
if @exist
|
36
32
|
result = separator + "\n"
|
37
|
-
result <<
|
38
|
-
result <<
|
33
|
+
result << MHTML_CONTENT_LOCATION << @id << "\n"
|
34
|
+
result << MHTML_CONTENT_ENCODING << "\n\n"
|
39
35
|
result << encoded << "\n\n"
|
40
36
|
end
|
41
37
|
end
|
@@ -44,6 +40,15 @@ module WebResourceBundler
|
|
44
40
|
return nil unless @exist
|
45
41
|
Base64.encode64(File.read(@path)).gsub("\n", '')
|
46
42
|
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def report_problem_if_file_not_found
|
47
|
+
if WebResourceBundler::Bundler.logger && !URI.parse(@path).absolute? && !@exist
|
48
|
+
WebResourceBundler::Bundler.logger.info("Image not found #{@path}")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
47
52
|
end
|
48
53
|
end
|
49
54
|
end
|
@@ -1,11 +1,15 @@
|
|
1
1
|
$:.unshift File.dirname(__FILE__)
|
2
|
+
|
2
3
|
require 'image_encode_filter/image_data'
|
3
4
|
require 'image_encode_filter/css_generator'
|
5
|
+
|
4
6
|
module WebResourceBundler::Filters::ImageEncodeFilter
|
5
7
|
class Filter < WebResourceBundler::Filters::BaseFilter
|
6
|
-
|
7
|
-
|
8
|
+
|
9
|
+
FILE_PREFIX = 'base64_'
|
10
|
+
IE_FILE_PREFIX = 'base64_ie_'
|
8
11
|
MHTML_FILE_PREFIX = 'mhtml_'
|
12
|
+
|
9
13
|
def initialize(settings, file_manager)
|
10
14
|
super settings, file_manager
|
11
15
|
@generator = CssGenerator.new(@settings, @file_manager)
|
@@ -16,42 +20,64 @@ module WebResourceBundler::Filters::ImageEncodeFilter
|
|
16
20
|
@generator.set_settings(settings)
|
17
21
|
end
|
18
22
|
|
23
|
+
#creates one new css file with mhtml content for IE < 8
|
24
|
+
#original css file content changed with images encoded in it in base64
|
25
|
+
#also its type changed to CSS because from this point it is valid only for
|
26
|
+
#normal browsers and IE > 7
|
19
27
|
def apply!(block_data)
|
20
|
-
|
28
|
+
new_files = []
|
21
29
|
block_data.styles.each do |file|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
file.path = encoded_filepath(file.path)
|
27
|
-
#we've created separate file for IE so current file should be marked as CSS only
|
28
|
-
file.types = [WebResourceBundler::ResourceFileType::CSS]
|
30
|
+
base_name = file.path
|
31
|
+
mhtml_css_file = create_mhtml_css_file(file)
|
32
|
+
mhtml_file = create_mhtml_file(file)
|
33
|
+
change_css_file!(file)
|
29
34
|
unless file.content.empty?
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
mhtml_file.content = @generator.construct_mhtml_content(images)
|
35
|
+
encode_images_in_css_file!(file)
|
36
|
+
images = change_images_to_mhtml_links!(mhtml_css_file, mhtml_filepath(base_name))
|
37
|
+
mhtml_file.content = @generator.construct_mhtml_content(images.values)
|
34
38
|
end
|
35
|
-
|
36
|
-
|
39
|
+
block_data.files << mhtml_css_file
|
40
|
+
block_data.files << mhtml_file
|
37
41
|
end
|
38
|
-
block_data.files += added_files
|
39
42
|
block_data
|
40
43
|
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def encode_images_in_css_file!(file)
|
48
|
+
@generator.encode_images!(file.content)
|
49
|
+
end
|
50
|
+
|
51
|
+
def change_images_to_mhtml_links!(file, mhtml_path)
|
52
|
+
@generator.encode_images_for_ie!(file.content, mhtml_path)
|
53
|
+
end
|
54
|
+
|
55
|
+
def change_css_file!(file)
|
56
|
+
file.path = css_filepath(file.path)
|
57
|
+
file.type = WebResourceBundler::ResourceFileType::BASE64_CSS
|
58
|
+
end
|
59
|
+
|
60
|
+
def create_mhtml_css_file(css_file)
|
61
|
+
WebResourceBundler::ResourceFile.new_mhtml_css_file(mhtml_css_filepath(css_file.path), css_file.content.dup)
|
62
|
+
end
|
63
|
+
|
64
|
+
def create_mhtml_file(css_file)
|
65
|
+
WebResourceBundler::ResourceFile.new_mhtml_file(mhtml_filepath(css_file.path))
|
66
|
+
end
|
41
67
|
|
42
|
-
#path
|
43
|
-
def
|
68
|
+
#path to new file with images encoded in base64 for normal browsers
|
69
|
+
def css_filepath(base_file_path)
|
44
70
|
File.join(@settings[:cache_dir], FILE_PREFIX + File.basename(base_file_path))
|
45
71
|
end
|
46
72
|
|
47
|
-
#path
|
48
|
-
def
|
73
|
+
#path to new file for IE with images encoded in it
|
74
|
+
def mhtml_css_filepath(base_file_path)
|
49
75
|
File.join(@settings[:cache_dir], IE_FILE_PREFIX + File.basename(base_file_path))
|
50
76
|
end
|
51
77
|
|
52
|
-
|
78
|
+
#path to file with mhtml content for IE
|
53
79
|
def mhtml_filepath(base_file_path)
|
54
|
-
File.join(@settings[:cache_dir], MHTML_FILE_PREFIX + File.basename(base_file_path,
|
80
|
+
File.join(@settings[:cache_dir], MHTML_FILE_PREFIX + File.basename(base_file_path, '.css') + '.mhtml')
|
55
81
|
end
|
56
82
|
|
57
83
|
end
|
@@ -1,67 +1,83 @@
|
|
1
1
|
module WebResourceBundler::RailsAppHelpers
|
2
2
|
|
3
|
+
DATA_URI_START = "<!--[if (!IE)|(gte IE 8)]><!-->"
|
4
|
+
DATA_URI_END = "<!--<![endif]-->"
|
5
|
+
MHTML_START = "<!--[if lte IE 7]>"
|
6
|
+
MHTML_END = "<![endif]-->"
|
7
|
+
|
3
8
|
def web_resource_bundler_process(&block)
|
4
9
|
#getting ActionView::NonConcattingString
|
5
10
|
#but we want simple string to escape problems
|
6
11
|
result = String.new(capture(&block))
|
7
|
-
|
8
|
-
version = Rails::VERSION::STRING
|
9
|
-
if !params['no_bundler'] and WebResourceBundler::Bundler.instance.settings_correct
|
12
|
+
if !params['no_bundler'] && WebResourceBundler::Settings.correct?
|
10
13
|
#we want to keep original string unchanged so we can return same content on error
|
11
|
-
block_data = WebResourceBundler::Bundler.
|
14
|
+
block_data = WebResourceBundler::Bundler.process(result.dup, request.host_with_port, request.protocol.gsub(/:\/\//,''))
|
12
15
|
#if everything ok with bundling we should construct resulted html content and change result
|
13
|
-
result = construct_block(block_data, WebResourceBundler::
|
14
|
-
end
|
15
|
-
case
|
16
|
-
when version >= '3.0.0' then return raw(result)
|
17
|
-
when (version >= '2.2.0' and version < '2.4.0') then concat(result)
|
18
|
-
else
|
19
|
-
concat(result, block.binding)
|
16
|
+
result = construct_block(block_data, WebResourceBundler::Settings.settings) if block_data
|
20
17
|
end
|
18
|
+
construct_result(Rails::VERSION::STRING, result, block)
|
21
19
|
end
|
22
20
|
|
23
21
|
def construct_block(block_data, settings)
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
end
|
30
|
-
else
|
31
|
-
#it normal browser - so just including base64 css
|
32
|
-
styles = block_data.files.select {|f| f.types.include?(WebResourceBundler::ResourceFileType::CSS)}
|
33
|
-
end
|
34
|
-
styles.each do |file|
|
35
|
-
url = File.join('/', file.path)
|
36
|
-
result << stylesheet_link_tag(url)
|
37
|
-
result << "\n"
|
38
|
-
end
|
39
|
-
block_data.scripts.each do |file|
|
40
|
-
url = File.join('/', file.path)
|
41
|
-
result << javascript_include_tag(url)
|
42
|
-
result << "\n"
|
43
|
-
end
|
22
|
+
result = ""
|
23
|
+
result << data_uri_part(block_data.base64_styles)
|
24
|
+
result << mhtml_part(block_data.mhtml_styles)
|
25
|
+
result << scripts_part(block_data.scripts)
|
26
|
+
|
44
27
|
result << block_data.inline_block unless block_data.inline_block.blank?
|
28
|
+
|
45
29
|
block_data.child_blocks.each do |block|
|
46
30
|
result << construct_block(block, settings)
|
47
31
|
end
|
32
|
+
|
48
33
|
unless block_data.condition.empty?
|
49
|
-
result = "<!--#{block_data.condition}>\n
|
34
|
+
result = "<!--#{block_data.condition}>\n#{result}<![endif]-->\n"
|
50
35
|
end
|
36
|
+
|
51
37
|
#removing unnecessary new line symbols
|
52
38
|
result.gsub!(/\n(\s)+/, "\n")
|
53
39
|
result
|
54
40
|
end
|
55
41
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
42
|
+
private
|
43
|
+
|
44
|
+
#constructs resulted html text
|
45
|
+
#method depends on rails version
|
46
|
+
def construct_result(version, result, block)
|
47
|
+
case
|
48
|
+
when version >= '3.0.0' then raw(result)
|
49
|
+
when version >= '2.2.0' && version < '2.4.0' then concat(result)
|
50
|
+
else
|
51
|
+
concat(result, block.binding)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def data_uri_part(styles)
|
56
|
+
result = DATA_URI_START + "\n"
|
57
|
+
styles.inject(result) do |data, file|
|
58
|
+
data << construct_file_link(file.path)
|
59
|
+
end
|
60
|
+
result << DATA_URI_END << "\n"
|
61
|
+
end
|
62
|
+
|
63
|
+
def mhtml_part(styles)
|
64
|
+
result = MHTML_START + "\n"
|
65
|
+
styles.inject(result) do |data, file|
|
66
|
+
data << construct_file_link(file.path)
|
63
67
|
end
|
64
|
-
|
68
|
+
result << MHTML_END + "\n"
|
69
|
+
end
|
70
|
+
|
71
|
+
def scripts_part(scripts)
|
72
|
+
scripts.inject("") do |data, file|
|
73
|
+
url = File.join('/', file.path)
|
74
|
+
data << javascript_include_tag(url) << "\n"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def construct_file_link(path)
|
79
|
+
url = File.join('/', path)
|
80
|
+
stylesheet_link_tag(url) << "\n"
|
65
81
|
end
|
66
82
|
|
67
83
|
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
class WebResourceBundler::Settings
|
3
|
+
|
4
|
+
DEFAULT_LOG_PATH = 'log/web_resource_bundler.log'
|
5
|
+
DEFAULT_RESOURCE_DIR = 'public'
|
6
|
+
DEFAULT_SETTINGS_PATH = 'config/web_resource_bundler.yml'
|
7
|
+
DEFAULT_CACHE_DIR = 'cache'
|
8
|
+
OBLIGATORY_SETTINGS = [:resource_dir, :log_path, :cache_dir]
|
9
|
+
|
10
|
+
class << self
|
11
|
+
|
12
|
+
attr_accessor :settings
|
13
|
+
|
14
|
+
#creates settings from config file
|
15
|
+
#and merging them with defaults
|
16
|
+
def create_settings(rails_root, rails_env)
|
17
|
+
config = self.read_from_file(rails_root, rails_env)
|
18
|
+
@settings = self.defaults(rails_root).merge(config)
|
19
|
+
@settings
|
20
|
+
end
|
21
|
+
|
22
|
+
#ensures that settings has obligatory keys present
|
23
|
+
def correct?(settings = @settings)
|
24
|
+
OBLIGATORY_SETTINGS.each { |key| return false unless settings.has_key?(key) }
|
25
|
+
true
|
26
|
+
end
|
27
|
+
|
28
|
+
#returns setting for particular filter, merged with common settings
|
29
|
+
def filter_settings(filter_name)
|
30
|
+
self.commons(@settings).merge(@settings[filter_name])
|
31
|
+
end
|
32
|
+
|
33
|
+
#setting request specific settings like domain and protocol
|
34
|
+
def set_request_specific_data!(settings, domain, protocol)
|
35
|
+
settings[:domain] = domain
|
36
|
+
settings[:protocol] = protocol
|
37
|
+
settings
|
38
|
+
end
|
39
|
+
|
40
|
+
#sets new settings by merging with existing
|
41
|
+
def set(settings)
|
42
|
+
@settings.merge!(settings)
|
43
|
+
end
|
44
|
+
|
45
|
+
def filter_used?(name)
|
46
|
+
@settings[name] && @settings[name][:use]
|
47
|
+
end
|
48
|
+
|
49
|
+
protected
|
50
|
+
|
51
|
+
#load settings from yaml file depending on environment
|
52
|
+
#if no settings found - returning empty hash
|
53
|
+
def read_from_file(rails_root, rails_env)
|
54
|
+
settings = {}
|
55
|
+
file_path = self.settings_file_path(rails_root)
|
56
|
+
if File.exist?(file_path)
|
57
|
+
all_settings = YAML::load(File.open(file_path))
|
58
|
+
if all_settings[rails_env]
|
59
|
+
settings = all_settings[rails_env]
|
60
|
+
settings[:resource_dir] = File.join(rails_root, DEFAULT_RESOURCE_DIR)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
settings
|
64
|
+
end
|
65
|
+
|
66
|
+
#returns path of config file
|
67
|
+
def settings_file_path(rails_root)
|
68
|
+
File.join(rails_root, DEFAULT_SETTINGS_PATH)
|
69
|
+
end
|
70
|
+
|
71
|
+
#creates defaults settings
|
72
|
+
def defaults(rails_root)
|
73
|
+
{
|
74
|
+
:resource_dir => File.join(rails_root, DEFAULT_RESOURCE_DIR),
|
75
|
+
:log_path => File.join(rails_root, DEFAULT_LOG_PATH),
|
76
|
+
:cache_dir => DEFAULT_CACHE_DIR,
|
77
|
+
:bundle_filter => {
|
78
|
+
:use => true
|
79
|
+
},
|
80
|
+
:cdn_filter => {
|
81
|
+
:use => false
|
82
|
+
},
|
83
|
+
:base64_filter => {
|
84
|
+
:use => true,
|
85
|
+
:max_image_size => 20
|
86
|
+
}
|
87
|
+
}
|
88
|
+
end
|
89
|
+
|
90
|
+
#settings common for all filters
|
91
|
+
def commons(settings)
|
92
|
+
{
|
93
|
+
:resource_dir => settings[:resource_dir],
|
94
|
+
:cache_dir => settings[:cache_dir]
|
95
|
+
}
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
end
|