Module: CantangoEditor::ApplicationHelper

Defined in:
app/helpers/cantango_editor/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#model_tag(model) ⇒ Object



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
# File 'app/helpers/cantango_editor/application_helper.rb', line 4

def model_tag model
  case model 
  when regex = /\/(.*)\//
    model = model[regex][$1]
    slash_tag =  :span, '/', :class => "model_regex_slash"
    modeltag =  :span, model, :class => "model_regex" 
    slash_tag + modeltag + slash_tag
  when regex = /^\^(\w+)/ # a category is prefixed with a '^<D-^>s'
    model = model[regex][$1]
    model = model.humanize
    
    # TODO: category aliases here
     :span, "`#{model}`", :class => "model_category"
  when regex = /\w+#\w+=.+/
    match = model[/(\w+)#(\w+)=(.+)/]
    model = match[$1]
    lstat = match[$2]
    rstat = match[$3]

    lstat_tag =  :span, lstat, :class => "model_relationship_lstat"
    rstat_tag =  :span, rstat, :class => "model_relationship_rstat"
    modeltag =  :span, model, :class => "model_relationship_model"
    equals_tag =  :span, '=', :class => "model_relationship_equals"
    sharp_tag =  :span, '#', :class => "model_relationship_sharp"

    modeltag + sharp_tag + lstat_tag + equals_tag + rstat_tag

  when regex = /\w+#\w+/
    match = model[/(\w+)#(\w+)/]
    model = match[$1]
    owner = match[$2]
 
    modeltag =  :span, model, :class => "model_ownership_model"
    owner_tag =  :span, owner, :class => "model_ownership_owner"       
    sharp_tag =  :span, '#', :class => "model_ownership_sharp"  

    modeltag + sharp_tag + owner_tag
  else
    model
  end
end