Class: Dust::Block

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
ActionView::Helpers::SanitizeHelper, ActionView::Helpers::TextHelper
Defined in:
app/models/dust/block.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find_active(uri) ⇒ Object



58
59
60
61
62
# File 'app/models/dust/block.rb', line 58

def self.find_active(uri)
  blocks = Block.all
  blocks.delete_if {|b| !b.show_me?(uri) }
  blocks
end

.gridObject



24
25
26
27
28
29
# File 'app/models/dust/block.rb', line 24

def self.grid
  grid = OpenStruct.new
  grid.columns = (1..12).map{ |i| [i.to_words.titleize, "#{i.to_words} columns"] }
  grid.offsets = (1..12).map{|i| ["Offset by #{i.to_words.titleize}", "offset-by-#{i.to_words}"]}
  grid
end

.page(search, page) ⇒ Object



31
32
33
# File 'app/models/dust/block.rb', line 31

def self.page(search, page)
  search(search).paginate(:per_page => 12, :page => page)
end

.regionsObject



13
14
15
16
17
18
19
20
21
22
# File 'app/models/dust/block.rb', line 13

def self.regions
  pretty_regions = []
  Dust.config.regions.each do |region|
    pretty_regions << [region.humanize.titleize, region]
  end
  Dust::Page.all.each do |page|
    pretty_regions.concat page.sections.map{ |s| ["#{page.nav_link} | #{s.title}", s.title.parameterize] } unless page.sections.blank?
  end
  pretty_regions
end

.search(search) ⇒ Object



35
36
37
38
39
40
41
# File 'app/models/dust/block.rb', line 35

def self.search(search)
  if search
    where("title LIKE ? OR body LIKE ?", "%#{search}%", "%#{search}%").where("show_title = ? OR 'show' != ?", false, '')
  else
    scoped
  end
end

.widget_listObject



83
84
85
86
87
88
89
90
91
92
93
# File 'app/models/dust/block.rb', line 83

def self.widget_list
  files = []
  paths = widget_filenames
  puts paths
  paths.each do |filename|
    if filename[0] != "." # if file is not hidden
      files.push filename.sub('_', '').gsub('.html.haml', '')
    end
  end
  files
end

Instance Method Details

#final_classesObject



43
44
45
# File 'app/models/dust/block.rb', line 43

def final_classes
  [column_span, column_offset, classes].join(" ")
end

#front_end_contentObject



64
65
66
67
68
69
70
# File 'app/models/dust/block.rb', line 64

def front_end_content
  options = {
    :block => self
  }

  Handlebar.render(body, options)
end

#pagesObject



72
73
74
75
76
77
78
79
80
81
# File 'app/models/dust/block.rb', line 72

def pages
  pages = []
  Page.all.each do |page|
    pages << page if url_list.include?(page.menu_item.url)
    pages << page if url_list.blank?
  end
  puts url_list.inspect
  puts pages.inspect
  pages
end

#show_me?(uri) ⇒ Boolean

Returns:

  • (Boolean)


51
52
53
54
55
56
# File 'app/models/dust/block.rb', line 51

def show_me?(uri)
  show = false
  show = true if (url_list.include?(uri) || url_list.blank?)
  show = true if (uri == "/" && url_list.include?("/#{Dust.config.root}"))
  show
end

#url_listObject



47
48
49
# File 'app/models/dust/block.rb', line 47

def url_list
  show.split("\r\n")
end