Class: Bijou::Component
- Inherits:
-
Object
- Object
- Bijou::Component
- Defined in:
- lib/bijou/component.rb
Overview
The Component class is used to represent Bijou pages, components, and containers. It is the default base class used during the code generation phase.
A component may use the base
directive to specify an alternative class. This can be done to provide helper functions to a page or to override certain methods, for example. Any custom base class should derive from Bijou::Component. The file implementing the class will also need to be part of the require_list array in Bijou::Config.
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
Class Method Summary collapse
-
.cache_filename ⇒ Object
Used for meaningful stack frames in errors (to work around an eval shortcoming).
-
.container ⇒ Object
If the <%! container %> directive is used, the derived class will return a physical path to the containing file.
-
.source_filename ⇒ Object
Used for meaningful stack frames in errors (to work around an eval shortcoming).
Instance Method Summary collapse
-
#fini ⇒ Object
The backing method for the %fini block.
-
#init(args) ⇒ Object
The backing method for the %init block.
-
#initialize(context) ⇒ Component
constructor
A new instance of Component.
-
#invoke(name, args = {}) ⇒ Object
A synonym for Context#invoke.
-
#print(*args) ⇒ Object
Behaves similarly to IO#print, except the output is rendered to the response stream.
-
#printf(format, *args) ⇒ Object
Behaves similarly to IO#printf, except the output is rendered to the response stream.
-
#puts(*args) ⇒ Object
Behaves similarly to IO#puts, except the output is rendered to the response stream.
- #raw_print ⇒ Object
- #raw_printf ⇒ Object
- #raw_puts ⇒ Object
-
#request ⇒ Object
A synonym for Context#request.
-
#response ⇒ Object
A synonym for Context#response.
-
#sinvoke(name, args = {}) ⇒ Object
A synonym for Context#sinvoke.
Constructor Details
#initialize(context) ⇒ Component
Returns a new instance of Component.
47 48 49 |
# File 'lib/bijou/component.rb', line 47 def initialize(context) @context = context end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
27 28 29 |
# File 'lib/bijou/component.rb', line 27 def context @context end |
Class Method Details
.cache_filename ⇒ Object
Used for meaningful stack frames in errors (to work around an eval shortcoming).
43 44 45 |
# File 'lib/bijou/component.rb', line 43 def self.cache_filename nil end |
.container ⇒ Object
If the <%! container %> directive is used, the derived class will return a physical path to the containing file.
31 32 33 |
# File 'lib/bijou/component.rb', line 31 def self.container nil end |
.source_filename ⇒ Object
Used for meaningful stack frames in errors (to work around an eval shortcoming).
37 38 39 |
# File 'lib/bijou/component.rb', line 37 def self.source_filename nil end |
Instance Method Details
#fini ⇒ Object
The backing method for the %fini block.
56 57 |
# File 'lib/bijou/component.rb', line 56 def fini end |
#init(args) ⇒ Object
The backing method for the %init block.
52 53 |
# File 'lib/bijou/component.rb', line 52 def init(args) end |
#invoke(name, args = {}) ⇒ Object
A synonym for Context#invoke.
65 66 67 |
# File 'lib/bijou/component.rb', line 65 def invoke(name, args={}) @context.invoke(name, args) end |
#print(*args) ⇒ Object
Behaves similarly to IO#print, except the output is rendered to the response stream.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/bijou/component.rb', line 77 def print(*args) sep = '' term = '' if $, sep = $, end if $\ term = $\ end @context.write(args.join(sep) + term) end |
#printf(format, *args) ⇒ Object
Behaves similarly to IO#printf, except the output is rendered to the response stream.
94 95 96 |
# File 'lib/bijou/component.rb', line 94 def printf(format, *args) @context.write(sprintf(format, *args)) end |
#puts(*args) ⇒ Object
Behaves similarly to IO#puts, except the output is rendered to the response stream.
71 72 73 |
# File 'lib/bijou/component.rb', line 71 def puts(*args) @context.writeline(args.join("\n")) end |
#raw_print ⇒ Object
24 |
# File 'lib/bijou/component.rb', line 24 alias raw_print print |
#raw_printf ⇒ Object
25 |
# File 'lib/bijou/component.rb', line 25 alias raw_printf printf |
#raw_puts ⇒ Object
23 |
# File 'lib/bijou/component.rb', line 23 alias raw_puts puts |
#request ⇒ Object
A synonym for Context#request.
99 100 101 |
# File 'lib/bijou/component.rb', line 99 def request @context.request end |
#response ⇒ Object
A synonym for Context#response.
104 105 106 |
# File 'lib/bijou/component.rb', line 104 def response @context.response end |
#sinvoke(name, args = {}) ⇒ Object
A synonym for Context#sinvoke.
60 61 62 |
# File 'lib/bijou/component.rb', line 60 def sinvoke(name, args={}) @context.sinvoke(name, args) end |