Class: Adocsite::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/adocsite/context.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(engine, request) ⇒ Context

Returns a new instance of Context.



4
5
6
7
8
9
10
11
# File 'lib/adocsite/context.rb', line 4

def initialize(engine, request)
  @engine = engine
  @request = request
  @type = request.type
  @context_vars = Hash.new

  build_vars
end

Instance Attribute Details

#typeObject (readonly)

Returns the value of attribute type.



3
4
5
# File 'lib/adocsite/context.rb', line 3

def type
  @type
end

Instance Method Details

#get_articleObject


result of calling these depends on context in which they are used, it depends on request that is made



102
103
104
# File 'lib/adocsite/context.rb', line 102

def get_article()
  @engine.content_loader.articles[@request.name]
end

#get_articles(category = nil) ⇒ Object



68
69
70
71
72
73
74
# File 'lib/adocsite/context.rb', line 68

def get_articles(category = nil)
  if category
  @engine.categories[category]
  else
  @engine.content_loader.articles.values
  end
end

#get_categoriesObject



64
65
66
# File 'lib/adocsite/context.rb', line 64

def get_categories()
  @engine.categories.values
end

#get_categoryObject



106
107
108
# File 'lib/adocsite/context.rb', line 106

def get_category()
  @engine.categories[@request.name]
end

#get_content_for_layoutObject


this is special kind of method that is used in layout template. it gets correct partial for the layout depending on context.



85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/adocsite/context.rb', line 85

def get_content_for_layout()
  get_partial(@type)
# if @type == "home"
# get_partial('home')
# elsif @type == "page"
# get_partial('page')
# elsif @type == "article"
# get_partial('article')
# elsif @type == "category"
# get_partial('category')
# end
end

#get_include(include_name) ⇒ Object



38
39
40
41
# File 'lib/adocsite/context.rb', line 38

def get_include(include_name)
  tpl = @engine.templates.get_include(include_name)
  tpl.render(self, @context_vars)
end

#get_layout(layout_name = "default") ⇒ Object



47
48
49
50
# File 'lib/adocsite/context.rb', line 47

def get_layout(layout_name = "default")
  tpl = @engine.templates.get_layout(layout_name)
  tpl.render(self, @context_vars)
end

#get_literal(literal_name) ⇒ Object



43
44
45
# File 'lib/adocsite/context.rb', line 43

def get_literal(literal_name)
  @engine.templates.get_literal(literal_name)
end

#get_pageObject



110
111
112
# File 'lib/adocsite/context.rb', line 110

def get_page()
  @engine.content_loader.pages[@request.name]
end

#get_pagesObject



60
61
62
# File 'lib/adocsite/context.rb', line 60

def get_pages()
  @engine.content_loader.pages.values
end

#get_partial(partial_name) ⇒ Object


these methods load other templates and render them in the same context in which current document is rendered



33
34
35
36
# File 'lib/adocsite/context.rb', line 33

def get_partial(partial_name)
  tpl = @engine.templates.get_partial(partial_name)
  tpl.render(self, @context_vars)
end

#is_context?(context_name) ⇒ Boolean


these methods behave the same in all contexts they are context independet

Returns:

  • (Boolean)


56
57
58
# File 'lib/adocsite/context.rb', line 56

def is_context?(context_name)
  @type == context_name
end


76
77
78
79
# File 'lib/adocsite/context.rb', line 76

def sitenav(type, name)
  request = Request.new(type, name)
  @engine.sitenav(request)
end