public
Description: The web app builder for Rails
Homepage: http://hobocentral.net
Clone URL: git://github.com/tablatom/hobo.git
hobo / hobo / taglibs / rapid_generics.dryml
100644 135 lines (121 sloc) 4.712 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<def tag="creation-details">
  <div class="creation-details">
    <span class="creator" param="by"><if:get_creator><view/></if:get_creator></span>
  </div>
</def>
 
<def tag="primary-content">
  <view class="primary-content" field="&this.class.primary_content_attribute" if="&this.class.primary_content_attribute" merge/>
</def>
 
<def tag="association-count">
  <a class="association-count #{this_field.to_s.underscore}" href="##{this_field.to_s.underscore}" merge>
    <count/>
  </a>
</def>
 
<def tag="base-card">
  <if test="&can_view?">
    <set has-heading="&this.class.name_attribute || all_parameters[:heading]"/>
    <set has-link="&has_heading && linkable?"/>
    <div class="card #{has_link ? 'linkable' : 'content'} #{'with-owner' if this.class.creator_attribute} #{type_name :dasherize => true}"
         merge-attrs>
      <div class="controls" param="controls">
        <a action="edit" class="edit" if="&!has_link && linkable?(:edit) && can_edit?" param="edit-link">Edit</a>
        <delete-button label="X" unless="&linkable?(:edit)" param/>
      </div>
 
      <h4 param="heading" if="&has_heading"><a><name/></a></h4>
      <div class="body" param="body">
        <div class="content" param="content" unless="&has_link">
          <primary-content/>
        </div>
        <creation-details param/>
        <do param="count">
          <set primary-collection="&primary_collection_name"/>
          <if test="&primary_collection">
            <span class="dependents"><count field="&primary_collection"/></span>
          </if>
        </do>
      </div>
    </div>
  </if>
</def>
 
<def tag="card">
  <if test="&can_view?">
    <%= poly = call_polymorphic_tag('card', attributes, parameters) %>
    <base-card unless="&poly" merge/>
  </if>
</def>
 
<def tag="search-card">
  <%= poly = call_polymorphic_tag('search-card', attributes, parameters) %>
  <card unless="&poly"/>
</def>
 
<def tag="collection">
  <set-scoped collection-contains-delete-button="&false">
    <%= poly = call_polymorphic_tag('collection', attributes, parameters) %>
    <base-collection if="&poly.nil?" merge/>
    <p class="empty-collection-message"
       if="&this.empty? || scope.collection_contains_delete_button"
       style="#{'display:none' if !this.empty?}"
       param="empty-message">
      No <name-for-collection lowercase/> to display
    </p>
  </set-scoped>
</def>
 
 
<def tag="base-collection" attrs="sortable, sortable-options"><%
  sortable &&= (first = this.first and
                first.respond_to?(:position_column) and
                reorder_url = object_url(this.member_class, :reorder, :method => :post) and
                can_edit?(first, first.position_column))
  if sortable
    singular_name = first.class.name.underscore
    attributes[:id] ||= "#{singular_name}_ordering"
  end
  collection_name = this.try.origin_attribute || this.member_class.name.underscore
  %>
  <ul class="collection #{collection_name.to_s.gsub('_', '-')}" merge-attrs>
    <li: id="&%(#{singular_name}_#{this.id}) if sortable" param>
      <div class="ordering-handle" param="handle" if="&sortable">&uarr;<br/>&darr;</div>
      <card param/>
    </li:>
  </ul>
  <%= if sortable && Hobo::Dryml.last_if
        opts = { :url => reorder_url,
                 :constraint => :vertical,
                 :overlap => :vertical,
                 :scroll => :window,
                 :handle => 'ordering-handle',
                 :complete => [visual_effect(:highlight, attributes[:id])]
                }
        opts.update(sortable_options) if sortable_options
        sortable_element attributes[:id], opts
      end
   %>
</def>
 
 
<def tag="collection-preview" attrs="limit, if-any">
  <% limit ||= 6 %>
  <do with="&this.limit(limit)">
    <unless test="&if_any && this.empty?">
      <set collection-name="&(this.try.origin_attribute || this.member_class.name.pluralize).to_s"/>
      <div class="collection-preview" merge-attrs>
        <header param>
          <h3 param="heading"><collection-name.titleize/></h3>
          <div if="&linkable? && this.count > limit" class="show-all" param="show-all-link">(<a>show all</a>)</div>
        </header>
        <collection merge-params>
          <card: class="small"/>
        </collection>
      </div>
    </unless>
  </do>
</def>
 
 
<def tag="new-link-or-form" attrs="model">
  <if test="&linkable?(model, :create, :method => :post)">
    <a to="&model" action="new" param="new-link"/>
    <else>
      <if with="&model.user_new current_user">
        <section class="create-new">
          <h2>New <type-name/></h2>
          <form><field-list param="new-field-list"/><submit label="Create"/></form>
        </section>
      </if>
    </else>
  </if>
</def>