Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
O
OHR Support
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
97
Issues
97
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
OHR Support
Commits
3c3eb2f7
Commit
3c3eb2f7
authored
Dec 26, 2011
by
Holger Just
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[#790] Register variables with an API
parent
dc5fd8bc
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
8 deletions
+26
-8
application_helper.rb
app/helpers/application_helper.rb
+1
-1
variables.rb
lib/chili_project/liquid/variables.rb
+25
-7
No files found.
app/helpers/application_helper.rb
View file @
3c3eb2f7
...
...
@@ -472,7 +472,7 @@ module ApplicationHelper
liquid_variables
=
get_view_instance_variables_for_liquid
liquid_variables
.
merge!
({
'current_user'
=>
User
.
current
})
liquid_variables
.
merge!
({
'toc'
=>
'{{toc}}'
})
# Pass toc through to replace later
liquid_variables
.
merge!
(
ChiliProject
::
Liquid
::
Variables
.
macro_backwards_compatibility
)
liquid_variables
.
merge!
(
ChiliProject
::
Liquid
::
Variables
.
all
)
# Pass :view in a register so this view (with helpers) can be used inside of a tag
text
=
liquid_template
.
render
(
liquid_variables
,
:registers
=>
{
:view
=>
self
,
:object
=>
obj
,
:attribute
=>
attr
})
...
...
lib/chili_project/liquid/variables.rb
View file @
3c3eb2f7
...
...
@@ -15,14 +15,32 @@
module
ChiliProject
module
Liquid
module
Variables
# Liquid "variables" that are used for backwards compatability with macros
#
# Variables are used in liquid like {{var}}
def
self
.
macro_backwards_compatibility
{
'macro_list'
=>
"Use the '{% variable_list %}' tag to see all Liquid variables and '{% tag_list %}' to see all of the Liquid tags."
}
class
LazyVariable
def
initialize
(
context
,
&
block
)
@block
=
block
@context
=
context
end
def
to_liquid
()
(
@block
.
arity
==
0
)
?
@block
.
call
:
@block
.
call
(
@context
)
end
end
# Register a Liquid variable.
# Pass a value to register a fixed variable or a block to create a lazy
# evaluated variable. The block can take the current context
def
self
.
register
(
name
,
value
=
nil
,
&
block
)
var
=
block_given?
?
Proc
.
new
(){
|
ctx
|
LazyVariable
.
new
(
ctx
,
&
block
)}
:
value
all
[
name
.
to_s
]
=
var
end
def
self
.
all
@variables
||=
{}
end
# DEPRACATED: This is just a hint on how to use Liquid introspection
register
"macro_list"
,
"Use the '{% variable_list %}' tag to see all Liquid variables and '{% tag_list %}' to see all of the Liquid tags."
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment