Class: RBT::Sinatra

Inherits:
Sinatra::Base
  • Object
show all
Includes:
Colours, Colours::E, HtmlTags::BaseModule
Defined in:
lib/rbt/sinatra/app.rb,
lib/rbt/sinatra/action_view.rb,
lib/rbt/sinatra/action_create.rb,
lib/rbt/sinatra/action_available_programs.rb

Constant Summary collapse

USE_THIS_PORT =
#

USE_THIS_PORT

#
'5580'
TITLE =
#

TITLE

#
'Web-API for the RBT project'
IS_ROEBE =
#

IS_ROEBE

#
true

Instance Method Summary collapse

Constructor Details

#initializeSinatra

#

initialize

#


79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/rbt/sinatra/app.rb', line 79

def initialize
  super()
  reset
  if IS_ROEBE
    require 'open'
    # ===================================================================== #
    # Tell us which port will be used:
    # ===================================================================== #
    target = "http://localhost:#{USE_THIS_PORT}/"
    e sfancy(target)
    Thread.new {
      sleep 1.0
      Open.in_browser(target)
    }
  end
end

Instance Method Details

#abr(i, hash) ⇒ Object

#

abr

#


171
172
173
# File 'lib/rbt/sinatra/app.rb', line 171

def abr(i, hash)
  HtmlTags.a(i, hash)+br
end

#resetObject

#

reset

#


99
100
# File 'lib/rbt/sinatra/app.rb', line 99

def reset
end

#return_available_actionsObject

#

return_available_actions

This method will list the available (registered) actions for the web-interface.

#


146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/rbt/sinatra/app.rb', line 146

def return_available_actions
  p('The following entry points are available:')+
  p(css_style: 'padding:10px; margin-left: 1em') {
    # ===================================================================== #
    # === /view
    # ===================================================================== #
    abr('/view',     content: '/view',   css_style: :bold)+
    # ===================================================================== #
    # === /create
    # ===================================================================== #
    abr('/create',   content: '/create', css_style: :bold)+
    # ===================================================================== #
    # === /available_programs
    # ===================================================================== #
    abr('/available_programs', content: '/available_programs', css_style: :bold)+
    # ===================================================================== #
    # === /install
    # ===================================================================== #
    abr('/install',  content: '/install', css_style: :bold) # /install
  }
end

#return_html_head_and_title_and_bodyObject

#

return_html_head_and_title_and_body

#


123
124
125
# File 'lib/rbt/sinatra/app.rb', line 123

def return_html_head_and_title_and_body
  '<html><head><title>'+TITLE+'</title></head><body>'
end

#return_main_indexObject

#

return_main_index

This method will return the main “index” - the first “page” that someone sees when using the sinatra-interface.

#


133
134
135
136
137
138
# File 'lib/rbt/sinatra/app.rb', line 133

def return_main_index
  return_html_head_and_title_and_body+
  'This is the <b>www-interface</b> for the RBT '\
  'project, using <b>sinatra</b>.'+
  return_available_actions
end
#
#


114
115
116
117
118
# File 'lib/rbt/sinatra/app.rb', line 114

def return_to_root_link
  p {
    a('/', content: 'Home')
  }
end