Class: Adocsite::Context
- Inherits:
-
Object
- Object
- Adocsite::Context
- Defined in:
- lib/adocsite/context.rb
Instance Attribute Summary collapse
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
-
#get_article ⇒ Object
————————————————– result of calling these depends on context in which they are used, it depends on request that is made.
- #get_articles(category = nil) ⇒ Object
- #get_categories ⇒ Object
- #get_category ⇒ Object
-
#get_content_for_layout ⇒ Object
————————————————– this is special kind of method that is used in layout template.
- #get_include(include_name) ⇒ Object
- #get_layout(layout_name = "default") ⇒ Object
- #get_literal(literal_name) ⇒ Object
- #get_page ⇒ Object
- #get_pages ⇒ Object
-
#get_partial(partial_name) ⇒ Object
————————————————– these methods load other templates and render them in the same context in which current document is rendered.
-
#initialize(engine, request) ⇒ Context
constructor
A new instance of Context.
-
#is_context?(context_name) ⇒ Boolean
————————————————– these methods behave the same in all contexts they are context independet.
- #sitenav(type, name) ⇒ Object
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
#type ⇒ Object (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_article ⇒ Object
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_categories ⇒ Object
64 65 66 |
# File 'lib/adocsite/context.rb', line 64 def get_categories() @engine.categories.values end |
#get_category ⇒ Object
106 107 108 |
# File 'lib/adocsite/context.rb', line 106 def get_category() @engine.categories[@request.name] end |
#get_content_for_layout ⇒ Object
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_page ⇒ Object
110 111 112 |
# File 'lib/adocsite/context.rb', line 110 def get_page() @engine.content_loader.pages[@request.name] end |
#get_pages ⇒ Object
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
56 57 58 |
# File 'lib/adocsite/context.rb', line 56 def is_context?(context_name) @type == context_name end |