Module: Teepee::CommanderMixins::ThinkingBicycleModels

Included in:
Teepee::Commander
Defined in:
lib/teepee/commander-mixins/thinking-bicycle-models.rb

Instance Method Summary collapse

Instance Method Details

#bookmarks_folder_id(id) ⇒ Object



61
62
63
# File 'lib/teepee/commander-mixins/thinking-bicycle-models.rb', line 61

def bookmarks_folder_id id
  id_command_handler id, :Folder, "folder", "folders", "folders/bookmarks_inline", "bookmarks"
end

#folder_id(id) ⇒ Object



65
66
67
# File 'lib/teepee/commander-mixins/thinking-bicycle-models.rb', line 65

def folder_id id
  id_command_handler id, :Folder
end

#forum_id(id) ⇒ Object



69
70
71
# File 'lib/teepee/commander-mixins/thinking-bicycle-models.rb', line 69

def forum_id id
  id_command_handler id, :Forum
end

#id_command_handler(id, klass, singular = klass.to_s.camelcase_to_snakecase, plural = singular.pluralize, partial = "#{plural}/inline", view = "") ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/teepee/commander-mixins/thinking-bicycle-models.rb', line 46

def id_command_handler(id,
                       klass,
                       singular = klass.to_s.camelcase_to_snakecase,
                       plural = singular.pluralize,
                       partial = "#{plural}/inline",
                       view="")
  if not id
    command_error "#{singular}_id: error: no #{singular} ID specified"
  elsif not id.to_s =~ /\A[0-9]+\z/
    command_error "#{singular}_id: error: invalid #{singular} ID specified"
  else
    tb_href "#{plural}/#{id.to_s}/#{view}", "#{klass.to_s} ##{id.to_s}"
  end
end

#image(expressions) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/teepee/commander-mixins/thinking-bicycle-models.rb', line 73

def image expressions
  expressions = strip expressions
  uri, *alt_text = expressions
  uri = ERB::Util.html_escape uri.to_html
  if not valid_uri? uri
    command_error "Not a valid URI for the image."
  else
    if alt_text.empty?
      html_tag :img, nil, {src: uri}
    else
      html_tag :img, nil, {src: uri, alt: alt_text.map(&:to_html).join.strip}
    end
  end
end

#keyword_id(id) ⇒ Object



88
89
90
# File 'lib/teepee/commander-mixins/thinking-bicycle-models.rb', line 88

def keyword_id id
  id_command_handler id, :Keyword
end


92
93
94
95
96
97
98
99
100
101
102
# File 'lib/teepee/commander-mixins/thinking-bicycle-models.rb', line 92

def link expressions
  expressions = strip expressions
  uri, *desc = expressions
  uri = ERB::Util.html_escape uri.to_html
  if not valid_uri? uri
    command_error "Not a valid URI."
  else
    desc = [uri] if desc.empty?
    html_tag :a, desc, {href: uri}
  end
end


104
105
106
# File 'lib/teepee/commander-mixins/thinking-bicycle-models.rb', line 104

def link_id id
  id_command_handler id, :Link
end

#mailto(email_address) ⇒ Object



108
109
110
111
112
113
114
115
# File 'lib/teepee/commander-mixins/thinking-bicycle-models.rb', line 108

def mailto email_address
  email_address = email_address.to_html
  if valid_email_address? email_address
    html_tag :a, [email_address], {href: "mailto:#{email_address}"}
  else
    command_error "I'm not sure that's a valid email address."
  end
end

#note_id(id) ⇒ Object



117
118
119
# File 'lib/teepee/commander-mixins/thinking-bicycle-models.rb', line 117

def note_id id
  id_command_handler id, :Note
end

#tag_id(id) ⇒ Object



121
122
123
# File 'lib/teepee/commander-mixins/thinking-bicycle-models.rb', line 121

def tag_id id
  id_command_handler id, :Tag
end

#tb_href(target, string) ⇒ Object



42
43
44
# File 'lib/teepee/commander-mixins/thinking-bicycle-models.rb', line 42

def tb_href target, string
  %{<a href="#{TB_COM}/#{target}">#{string}</a>}
end

#user(user) ⇒ Object



125
126
127
128
129
130
131
# File 'lib/teepee/commander-mixins/thinking-bicycle-models.rb', line 125

def user user
  if not user
    command_error "user: error: no user specified"
  else
    tb_href "users/#{user}", user.to_html
  end
end