Class: Dictionaries::Sinatra

Inherits:
Sinatra::Base
  • Object
show all
Includes:
Colours, Colours::E
Defined in:
lib/dictionaries/sinatra/app.rb,
lib/dictionaries/sinatra/english_to_german.rb

Constant Summary collapse

USE_THIS_PORT =
#

USE_THIS_PORT

#
'5252'

Instance Method Summary collapse

Constructor Details

#initializeSinatra

#

initialize

#

35
36
37
38
39
# File 'lib/dictionaries/sinatra/app.rb', line 35

def initialize
  super()
  reset
  consider_opening_the_page_in_the_browser
end

Instance Method Details

#consider_opening_the_page_in_the_browserObject

#

consider_opening_the_page_in_the_browser

#

50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/dictionaries/sinatra/app.rb', line 50

def consider_opening_the_page_in_the_browser
  if ::Dictionaries.is_on_roebe?
    require 'open_in_browser'
    # ===================================================================== #
    # Tell us which port will be used:
    # ===================================================================== #
    target = "http://localhost:#{USE_THIS_PORT}/"
    e sfancy(target)
    Thread.new {
      sleep 1.0
      OpenInBrowser[target]
    }
  end
end

#html_header_default_title_and_start_of_the_body_tagObject

#

html_header_default_title_and_start_of_the_body_tag

#

67
68
69
70
71
# File 'lib/dictionaries/sinatra/english_to_german.rb', line 67

def html_header_default_title_and_start_of_the_body_tag
  "<html>\n"\
  "<title>Dictionaries</title>\n"\
  "<body>\n"
end

#resetObject

#

reset

#

44
45
# File 'lib/dictionaries/sinatra/app.rb', line 44

def reset
end

#return_english_to_german_formObject

#

return_english_to_german_form

#

25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/dictionaries/sinatra/english_to_german.rb', line 25

def return_english_to_german_form
  route_to_this_action = '/english_to_german/'
  html_header_default_title_and_start_of_the_body_tag+
  h3('Input an english word next to see the translation.')+
  div(css_style: 'padding: 0.1em') {
    p(
      '<b>Enter the word here:</b>', css_style: 'padding:0.15em'
    )+
    form(action: route_to_this_action, id: 'english_to_german', css_style: 'margin-left:1em; margin-top:2px') {
      '<input type="text" name="user_input" style="border:3px solid slateblue; padding: 4px"><br>'+
      return_search_button
    }
  }
end

#return_search_buttonObject

#

return_search_button

#

76
77
78
79
80
# File 'lib/dictionaries/sinatra/english_to_german.rb', line 76

def return_search_button
  '<input type="submit" name="user_input_submit" value="Search" '\
  'style="font-weight: bold; font-size: larger; '\
  'border: 2px dotted slateblue; margin: 4px">'
end