Class: WebResourceBundler::BlockData

Inherits:
Object
  • Object
show all
Defined in:
lib/web_resource_bundler/content_management/block_data.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(condition = "") ⇒ BlockData

Returns a new instance of BlockData.



5
6
7
8
9
10
# File 'lib/web_resource_bundler/content_management/block_data.rb', line 5

def initialize(condition = "")
  @inline_block = ""
  @files        = []
  @condition    = condition
  @child_blocks = []
end

Instance Attribute Details

#child_blocksObject

Returns the value of attribute child_blocks.



3
4
5
# File 'lib/web_resource_bundler/content_management/block_data.rb', line 3

def child_blocks
  @child_blocks
end

#conditionObject

Returns the value of attribute condition.



3
4
5
# File 'lib/web_resource_bundler/content_management/block_data.rb', line 3

def condition
  @condition
end

#filesObject

Returns the value of attribute files.



3
4
5
# File 'lib/web_resource_bundler/content_management/block_data.rb', line 3

def files
  @files
end

#inline_blockObject

Returns the value of attribute inline_block.



3
4
5
# File 'lib/web_resource_bundler/content_management/block_data.rb', line 3

def inline_block
  @inline_block
end

Class Method Details

.all_childs(block_data) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/web_resource_bundler/content_management/block_data.rb', line 43

def self.all_childs(block_data)
  result = []
  result << block_data
  block_data.child_blocks.each do |child|
    result += BlockData.all_childs(child)
  end
  result
end

Instance Method Details

#all_filesObject



35
36
37
38
39
40
41
# File 'lib/web_resource_bundler/content_management/block_data.rb', line 35

def all_files
  result = self.files
  self.child_blocks.each do |child|
    result += child.all_files
  end
  result
end

#apply_filters(filters) ⇒ Object



52
53
54
55
56
57
58
59
# File 'lib/web_resource_bundler/content_management/block_data.rb', line 52

def apply_filters(filters)
  if filters.any?
    filters.each do |filter|
      items = BlockData.all_childs(self)
      items.each { |block_data| filter.apply!(block_data) } 
    end      
  end
end

#base64_stylesObject



20
21
22
# File 'lib/web_resource_bundler/content_management/block_data.rb', line 20

def base64_styles
  @files.select { |f| WebResourceBundler::ResourceFileType::CSS_TYPES.include?(f.type)}
end

#cloneObject



28
29
30
31
32
33
# File 'lib/web_resource_bundler/content_management/block_data.rb', line 28

def clone
  clon              = self.dup 
  clon.files        = self.files.map {|f| f.clone}
  clon.child_blocks = clon.child_blocks.any? ? self.child_blocks.map { |block| block.clone } : []
  clon
end

#mhtml_stylesObject



24
25
26
# File 'lib/web_resource_bundler/content_management/block_data.rb', line 24

def mhtml_styles
  @files.select { |f| WebResourceBundler::ResourceFileType::MHTML_TYPES.include?(f.type)}
end

#scriptsObject



16
17
18
# File 'lib/web_resource_bundler/content_management/block_data.rb', line 16

def scripts
  @files.select { |f| f.type[:ext] == 'js'}
end

#stylesObject



12
13
14
# File 'lib/web_resource_bundler/content_management/block_data.rb', line 12

def styles
  @files.select { |f| f.type[:ext] == 'css' } 
end