Class: Cyberweb::Sinatra

Inherits:
Sinatra::Base
  • Object
show all
Includes:
CustomExtensions
Defined in:
lib/cyberweb/sinatra/base.rb,
lib/cyberweb/sinatra/custom_extensions.rb,
lib/cyberweb/sinatra/base/use_this_port.rb,
lib/cyberweb/sinatra/base/set_use_this_port.rb

Defined Under Namespace

Modules: CustomExtensions

Constant Summary collapse

DEFAULT_PORT_TO_USE =
#

DEFAULT_PORT_TO_USE

#
'4567'

Class Method Summary collapse

Instance Method Summary collapse

Methods included from CustomExtensions

#abr, #are_we_using_sinatra?, #escape_html, #merge_interface, #not_yet_implemented, #query_string?, #temp_dir?, #web_params?

Constructor Details

#initialize(i = ARGV, use_this_port = ::Cyberweb::Sinatra.use_this_port?, shall_we_open_in_the_browser = true) ⇒ Sinatra

#

initialize

The second argument is the port.

#


38
39
40
41
42
43
44
45
46
# File 'lib/cyberweb/sinatra/base.rb', line 38

def initialize(
    i                            = ARGV,
    use_this_port                = ::Cyberweb::Sinatra.use_this_port?,
    shall_we_open_in_the_browser = true
  )
  super()
  reset
  consider_opening_on_this_port(use_this_port) if shall_we_open_in_the_browser
end

Class Method Details

.set_use_this_port(i = ::Cyberweb::Sinatra.use_this_port?) ⇒ Object

#

Cyberweb::Sinatra.set_use_this_port

#


23
24
25
26
27
28
# File 'lib/cyberweb/sinatra/base/set_use_this_port.rb', line 23

def self.set_use_this_port(
    i = ::Cyberweb::Sinatra.use_this_port?
  )
  @use_this_port = i
  Sinatra.set(:port, i)
end

.start_sinatra_interfaceObject

#

Cyberweb::Sinatra.start_sinatra_interface

#


150
151
152
# File 'lib/cyberweb/sinatra/base.rb', line 150

def self.start_sinatra_interface
  ::Cyberweb::Sinatra.run!
end

.use_this_port?Boolean

#

Cyberweb::Sinatra.use_this_port?

#

Returns:

  • (Boolean)


36
37
38
# File 'lib/cyberweb/sinatra/base/use_this_port.rb', line 36

def self.use_this_port?
  @use_this_port
end

Instance Method Details

#consider_opening_on_this_port(use_this_port) ⇒ Object

#

consider_opening_on_this_port

#


70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/cyberweb/sinatra/base.rb', line 70

def consider_opening_on_this_port(
    use_this_port
  )
  case use_this_port
  # ======================================================================= #
  # === :default
  # ======================================================================= #
  when :default
    use_this_port = ::Cyberweb::Sinatra.use_this_port?
  end
  if ::Cyberweb.is_on_roebe? and
     !use_this_port.nil? and
     use_this_port # Check for false here.
    # ===================================================================== #
    # Tell us which port will be used:
    # ===================================================================== #
    target = "http://localhost:#{use_this_port}/"
    Cyberweb.try_to_open_this_URL_via_the_browser(target, use_this_port)
  end
end

#input_type_submitObject

#

input_type_submit

#


142
143
144
# File 'lib/cyberweb/sinatra/base.rb', line 142

def input_type_submit
  '<input type="submit" name="user_input_submit" value="Search" class="default_submit">'
end

#input_type_user_inputObject

#

input_type_user_input

#


135
136
137
# File 'lib/cyberweb/sinatra/base.rb', line 135

def input_type_user_input
  '<input type="text" name="user_input" style="border:3px solid slateblue; padding: 4px">'
end

#resetObject

#

reset

#


51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/cyberweb/sinatra/base.rb', line 51

def reset
  # ======================================================================= #
  # === @index_of_hyperlinks
  # ======================================================================= #
  @index_of_hyperlinks = ''.dup
  # ======================================================================= #
  # === @root_string
  # ======================================================================= #
  @root_string = '<html><head>'\
                 '<title>Hello world!</title>'\
                 '<body>'\
                 '<h1>Hello world</h1>'\
                 '</body>'\
                 '</html>'.dup
end
#

This method will bundle together the different indices containing the hyperlinks that may/will be shown on the root-directory.

#


97
98
99
# File 'lib/cyberweb/sinatra/base.rb', line 97

def return_index_of_hyperlinks
  @index_of_hyperlinks
end

#return_root_stringObject

#

return_root_string

The root-string will contain the main index that is displayed when the user visits the page initially.

#


119
120
121
# File 'lib/cyberweb/sinatra/base.rb', line 119

def return_root_string
  @root_string
end

#set_port(i = USE_THIS_PORT) ⇒ Object

#

set_port

This unfortunately does not work right now. The idea was to call the set-method on the toplevel.

#


107
108
109
110
111
# File 'lib/cyberweb/sinatra/base.rb', line 107

def set_port(
    i = USE_THIS_PORT
  )
  set(:port, USE_THIS_PORT) # Delegate towards Sinatra::Base here.
end