DRYML partly uncovered
----------------------------------
This took some investigation into the internals of Hobo to uncover!

Most of the useful functions can be found in:
- libs/hobo/dryml/template_environment.rb
- libs/hobo/hobo_helper.rb


Shorthand for type of context
-----------------------------
this_type -> this.class


Test if a certain parameter is present?
----------------------------
all_parameters.tr?


Get View hints for field
------------------------
this.member_class.try.view_hints.try.field_name(..)


Get current Hobo theme
----------------------
Hobo.current_theme


Iterating over a list
----------------------
<repeat: join=","> ...</repeat>
These helpers are available within:
- repeat_item (NEW in edge!), the current item in the iteration
- first_item?
- last_item?

NOTE: I guess I could use this for my ExtJS case!
=================================================

Repeat uses this helper:

def context_map(enum = this)
  # TODO: Calls to respond_to? in here can cause the full collection
hiding behind a scoped collection to get loaded
  res = []

  scope.new_scope(:repeat_collection => enum, :even_odd =>
'odd', :repeat_item => nil) do
    if enum.respond_to?(:each_pair)
      enum.each_pair do |key, value|
        scope.repeat_item = value
        ...
        res << yield
        ...
      end
    end
  res
end

Note that it yields back to the tag def to render internal tags as
each list item is iterated!

----

Create a new DOM element dynamically
--------------------------------
Returns a string in the form of a tag "<yyy ... /> or <xxx ...>
[content] </xxx>"

def element(name, attributes, content=nil, escape = true, empty =
false, &block)
  unless attributes.blank?
    # build attributes for tag
    attrs = []
    if escape
      attributes.each do |key, value|
        next unless value
        key = key.to_s.gsub("_", "-")
        ...
        attrs << %(#{key}="#{value}")
      end
      ...
    attr_string = " #{attrs.sort * ' '}" unless attrs.empty?
  end

  # build tag <...>
  content = new_context { yield } if block_given?
  res = if empty
          "<#{name}#{attr_string}#{scope.xmldoctype ? ' /' : ''}>"
        else
          "<#{name}#{attr_string}>#{content}</#{name}>"
        end
  # how to "insert" the tag!?
  if block_called_from_erb? block
    concat res
  else
    res
  end
end

Iterating Hobo models
---------------------
Hobo::Model.all_models.map do |m|
end

Calling polymorphic tags
-------------------------
call_polymorphic_tag(name, *args)
  name = name.to_s.gsub('-', '_')
  type = args.first.is_a?(Class) ? args.shift : nil
  attributes, parameters = args
  tag = find_polymorphic_tag(name, type)

Fx call_polymorphic_tag("mytag", "Recipe", all_attributes,
all_parameters)

here "Recipe" will be used as the type indicator for polymorphism,
then shifted out of args
----


Get most likely label identifier for object
-------------------------------------------

if (attr = this.try.origin_attribute)
  name = attr.to_s


Permission system related
-------------------------
can_edit?(*args)
can_edit?
can_view?(x)
can_create?(object=this)
can_update?(object=this)
can_delete?(object=this)

Get controller for object
-------------------------
controller_for(obj)

Creating url to object action:
-----------------------
Note: handles ownership etc.

def object_url(obj, *args)
  params = args.extract_options!
  action = args.first._?.to_sym
  options, params = params.partition_hash
([:subsite, :method, :format])
  ...
  if action == :new
    action_path = "#{obj.origin_attribute}/new"
    action = :"new_for_#{owner_name}"
  elsif action.nil?
    action_path = obj.origin_attribute
    if method.to_s == 'post'
      action = :"create_for_#{owner_name}"
    else
      action = :"index_for_#{owner_name}"
    end
  end
end


Fx
object_url(recipe, 'show')

object_url(recipe, :method => :get) -> show recipe

object_url(recipe, :method => :post) -> create_for_...

-------------------------------------------
The mysterious but powerful ones (I think!)
---------------------------------------------------------
No documentation here and can't figure out their role and exactly what
they do; anyone?

def call_tag_parameter_with_default_content(the_tag, attributes,
default_content, overriding_content_proc)
def call_tag_parameter(the_tag, attributes, parameters,
caller_parameters, param_name)
def override_and_call_tag(the_tag, general_attributes,
general_parameters, overriding_attributes, overriding_parameters)

# This method is used where 'param' is declared on a tag that is
# itself a parameter tag.  Takes two procs that each return a pair
# of hashes (attributes and parameters). Returns a single proc
# that also returns a pair of hashes - the merged atributes and
# parameters.
def merge_tag_parameter(general_proc, overriding_proc)

def render_tag(tag_name, attributes)



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Hobo 
Users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/hobousers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to