-- ->fill should do the right thing when the current element is DL etc.
-- when doing ->select and there's only one optgroup do the right thing
-- table helpers ???
-- review docs especially the form docs.
-- lace-context, lace-repeat ...?
-- <$.method> => sub method { $self, $dom, %stuff } ...??
      <tag lace-call='$.render_user?links=$.links' />
-- Above would work for components also like
    <View-Form action=$.action>
      <View-Form.input name='user' />
    </View-Form>
-- <div lace-id='content' lace-id@href='link'>Stuff</div>
    $dom->lace_data
      ->content($self->story)
      ->link($self->uri('info'));
-- Review all docs and maybe cookbook?
-- allow <tag lace-component='View-User'>
        <tag lace-component='View-User?links=$.links' /> ???
-- ALlow template to assign method on attribute??
      <tag class=[$.set_class] />  ==> sub { my ($self, $tag_dom) = @_; return 'class' }


---
### Annotations example

  package MyApp::DisplayModel::User;

  use Moose;
  use Lace::AttributeAnnotations;
  use MyApp::Types;

  has 'name', (
    is=>'ro',
    isa=>String,
    display_html=>sub {
      my ($self, $data, $dom) = @_;
      $dom->at('#user-name', $data);
    });

  has 'friends, (
    is=>'ro',
    isa=>ArrayRef[Person],
    display_hmtl=> sub {
      my ($self, $data, $dom) = @_;
      $dom->ul('#friends, $data)
  );

# This idea will work better with binds

== How to let a compent control the init args of subcomponents

# The idea is that the sub component gets it args from
# the contaiing componet
 <lace-form errors='$.form.errors' ...>
  <input errors='$.errors.age' value='$.values.age' title='$self.title' />
 </lace-form>

Starting to lean toward something like

$dom->at('#content')
  ->content( $self->process_components( $self->content))

or mayb $self->content->process_components( ctx=>$self->formdata, ...)

might have to move the concept of compoents into Template::Lace::DOM 
to get this right. 

Ok now if we move components to the DOM we can support 
->attach

==== END

<Lace-Status.show>
<p>
  This is a test <info:status/>.  For More information
  click <a info:href >here</a>
</p>
</Lace-Status.show>

package MyApp::Lace::Status;

sub show {
  my ($self, $dom) = @_;
  $dom->bind('info', 
    status => $self->status,
    href => $self->uri('info'), # canonically +{ href => $self->uri('info') },
  );
}

<section id="todos">
  <lace-todos.count>
    <p>
      Hi there <person:name />! Here's you're work list!
    </p>
    <ol>
      <li data-person='todos'><todo:name/></li>
    </ol>
  </lace-todos.count>
</section>

package MyApp::Lace::Todos;

sub dispatch { 
  my ($self, $name, @args) = @_;
  return $self->display(@args) if $name eq 'count';
}

sub display {
  my ($self, $dom) = @_;
  $dom->bind('person', 
    name => $self->person->name,
    todos => sub { $self->list_todos($_) },
  );
}

sub list_todos {
  my ($self, $dom) = @_;
  $dom->repeat(sub {
    my ($dom, $todo) = @_;
    $dom->bind('todo', name => $todo->name)
  }, $self->person->todos);
}

# =================

sub process_dom {
  my ($self, $dom) = @_;
  $dom->bind('links',
    add_task => { action=>$self->uri('add') },
    clear_completed => { action=>$self->uri('clear_completed') },
    show_all => $self->build_summary_url('all'),
    show_active => $self->build_summary_url('active'),
    show_completed => $self->build_summary_url('completed'),
  )->bind('todos',
    active_count => $self->active_task_count,
    set => sub { $self->list_todos($_) },
  );
}

  my ($self, $dom) = @_;
  $dom->bind('links',
    add_task => { action=>$self->uri('add') },
    clear_completed => { action=>$self->uri('clear_completed') },
    show_all => $self->build_summary_url('all'),
    show_active => $self->build_summary_url('active'),
    show_completed => $self->build_summary_url('completed'),
  )->bind('todos',
    active_count => $self->active_task_count,
    set => sub { $self->list_todos($_) },
  );
}


sub build_summary_url {
  my ($self, $set) = @_;
  return +{
    action => $self->uri('summary',{q=>$set}),
    class => $self->set eq $set ? 'selected':undef,
  };
}

sub list_todos {
  my ($self, $dom) = @_;
  $dom->repeat(sub {
    my ($dom, $todo) = @_;
    $dom->bind('todo',
      update_action => +{ action => $self->uri('/task/update', [$todo->todo_id]) },
      destroy_action => +{ action => $self->uri('/task/delete', [$todo->todo_id]) },
      display_label => $todo->title,
      title_input => sub { $_->value($todo->title) }
      task_id => +{ 'id+' => $todo->id },
      form_id => +{ 'id+' => $todo->id },
      data_id => +{ 'data-task' => $todo->id },
      completed => sub { $self->mark_completed($_) },
    );
  }, $self->todos);
}

sub mark_completed {
  my ($self, $dom) = @_;
  $dom->data('is_complete',
    'checkbox@checked' => $self->completed,
    'display_class@class' => ($todo->completed ? "completed": undef),
  );
}


=======

<section id="todos">
  <lace-todos.count>
    <p>
      Hi there <span data-person='name'>PERSON</span>! Here's you're work list!
    </p>
      <ol>    
        <li data-person='todos'>
          <span data-todo='title'>THING TODO</span>
        </li>
      </ol>
  </view-todos>
</section>

package MyApp::Lace::Todos;

sub dispatch { 
  my ($self, $name, @args) = @_;
  return $self->display(@args) if $name eq 'count';
}

sub display {
  my ($self, $dom) = @_;
  $dom->data('person', 
    name => $self->person->name,
    todos => sub { $self->list_todos($_) },
  );
}

sub list_todos {
  my ($self, $dom) = @_;
  $dom->repeat(sub {
    my ($dom, $todo) = @_;
    $dom->data('todo', name => $todo->name)
  }, $self->person->todos);
}

=======

## The idea here is to locallzie $_ to self and %_ to 'by'
## for easier??

<section id="todos">
    <p data-lace='$.info>
      Hi there <span data-person='name'>
        <a data-person@href='resumelink'>
          PERSON
        </a></span>! Here's you're work list!
    </p>
      <ol>
        <li data-lace='@.list-todos'>
          <span data-todo='title Str'>THING TODO</span>
        </li>
      </ol>
</section>

package MyApp::Lace::Todos;

sub info {
  $_{person}
    ->name($_->person->name)
    ->resumelink($_->person->resume_link);
}

sub list_todos {
  return $_->person
    ->todos
    ->map(sub {
      $_{todo}->clone
        ->title($_->title);
    });
}

---

<li class=[.listclass]>
  ...
</li>


sub listclass {
  my ($self, $li) = @_;
  return $self->completed ? 'completed : undef;
}

===

sub template {qq[
  <ol>
    <view-todo task=$.task />
  </ol>
]}

sub process_dom {
  my ($self, $dom) = @_;
  $dom->component('view-todo')
    ->first
    ->repeat(sub {
        my ($dom, $task) = @_;
        $dom->process_component({task=>$task})
      }, $self->tasks);
}

---

sub template { '<ol></ol>' }

sub process_dom {
  my ($self, $dom) = @_;
  $dom->append_child($self->ctx->view('Todo', task=>$_)
    for @{$self->tasks};
}

--------

<ul lace-method="$.display_links"
    class="nav navbar-nav navbar-right">
  <li><a lace='link_title'
    return $dom;
  }, $self->links);
}

----------
-- EXAMPLE that lets template author set a context
----------

<ul @repeat="$.links" lace-method="$.display_links"
    class="nav navbar-nav navbar-right">
  <li><a lace='link_title'
      lace@href='href'
      lace@class='is_active'>
    Link
  </a></li>
</ul>

-- Should the render 'at' methods retunr the DOM or do they 
-- get to just modify it inline like 'process_fdom'..?

<$.render_links linkbase='/foo'>
  <section>
    <p><lace:title/></p>
    <ul>
      <li>
        <lace:links>
          <a lace@href='link'>
            <lace:description/>
          </a>
        </lace:links>
      </li>
    </ul>
  </section>
</$.render_links>

<section lace-do='$.render_links?linkbase=/foo'>
  <p lace='title'></p>
  <ul>
    <li lace='links'>
      <a lace='description'
          lace@href='link'>
        Link Link
      </a>
    </li>
  </ul>
</section>

sub render_links {
  my ($self, $dom, %args) = @_;
  $dom->by
    ->title('Hello World')
    ->links(sub {
      my ($li) = @_;
      $li->repeat(sub {
        my ($cloned_li$, $link) = @_;
        $cloned_li->by
          ->description($link->description)
          ->link($link->url($arg{linkbase}));
        return $cloned_li;
      }, $self->links);
      return $li;
    });
}

sub render_links {
  my ($self, $dom, %args) = @_;
  $dom->by
    ->title('Hello World')
    ->repeat::links($self->curry::render_link, $self->links);

    ->links(sub { $_->repeat($self->curry::render_link, $self->links) })

  $dom->for('#links', sub {
    $_->repeat($self->curry::render_link, $self->links);
  })

  $dom->repeat::for('#links', $self->curry::render_link, $self->links)

}

sub render_link {
  my ($self, $li, $link) = @_;
  return $li->by
    ->description($link->description)
    ->link($link->url($arg{linkbase}));
}

sub render_links {
  my ($self, $dom, %args) = @_;
  $dom->fill({
    title => 'Hello World',
    links => sub { shift->repeat(self->curry::render_link($arg{linkbase}), $self->links) },
  });
}

sub render_link {
  my ($self, $li, $base, $link) = @_;
  $li->fill({
    description => $link->description,
    link => sub { shift->attr(href=> $link->url($base)),
  });
}



      $dom->at('#links')->repeat(sub {
        my ($cloned_li$, $link) = @_;
        $cloned_li->by
          ->description($link->description)
          ->link($link->url($arg{linkbase}));
        return $cloned_li;
      }, $self->links);


      $dom->repeat_for('#links', sub { ... }, $self->links); 
