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



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

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

Instance Method Details

#all_filesObject



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

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

#apply_filters(filters) ⇒ Object



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

def apply_filters(filters)
  unless filters.empty?
    filters.each do |filter|
      items = BlockData.all_childs(self)
      items.each do |block_data|
        filter.apply!(block_data)
      end
    end      
  end
end

#cloneObject



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/web_resource_bundler/content_management/block_data.rb', line 23

def clone
  clon = self.dup 
  clon.files = self.files.map {|f| f.clone}
  if clon.child_blocks.size > 0
    clon.child_blocks = self.child_blocks.map do |block|
      block.clone
    end
  else
    clon.child_blocks = []
  end
  clon
end

#scriptsObject



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

def scripts
  @files.select {|f| f.types.include?(WebResourceBundler::ResourceFileType::JS)}
end

#stylesObject



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

def styles
  @files.select do |f|
    !([WebResourceBundler::ResourceFileType::CSS, 
      WebResourceBundler::ResourceFileType::IE_CSS] & f.types).empty?
  end
end