Class: Dust::Handlebar

Inherits:
Mustache
  • Object
show all
Defined in:
app/models/dust/handlebar.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



15
16
17
18
19
20
21
# File 'app/models/dust/handlebar.rb', line 15

def method_missing(name, *args, &block)
  if name.to_s =~ /^block_(\d+)/
    block($1)
  else
    return super
  end
end

Instance Method Details

#app_configObject



4
5
6
7
8
# File 'app/models/dust/handlebar.rb', line 4

def app_config
  raw_config = File.read("#{Rails.root}/config/app_config.yml")
  yaml_data = YAML.load(raw_config) 
  Hashie::Mash.new(yaml_data)
end

#block(id) ⇒ Object



10
11
12
13
# File 'app/models/dust/handlebar.rb', line 10

def block(id)
  @block = Block.find_by_id(id)
  @block.front_end_content
end

#blocksObject



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

def blocks
  Block.all
end


35
36
37
# File 'app/models/dust/handlebar.rb', line 35

def menu
  MenuItem.all
end

#recentObject



47
48
49
50
51
52
53
54
55
56
# File 'app/models/dust/handlebar.rb', line 47

def recent
  Post.recent.map{ |post|
    {
    :title         => post.title,
    :content          => post.preview,
    :published_at  => post.published_date,
    :slug          => post.kind == "workshop" ? "workshops" : "resources"
    }
  }
end

#respond_to?(method) ⇒ Boolean

Returns:

  • (Boolean)


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

def respond_to?(method)
  if method.to_s =~ /^block_(\d+)/
    method.to_s =~ /^block_(\d+)/
  else
    super
  end
end

#slidesObject



39
40
41
42
43
44
45
# File 'app/models/dust/handlebar.rb', line 39

def slides
  Nivo::Slide.rotate.map{ |slide|
    {
    :image         => slide.image.url
    }
  }
end