Class: Objectified::HtmlTags::Img

Inherits:
Cyberweb::Objectified::HtmlTags::Base show all
Defined in:
lib/cyberweb/objectified/html_tags/img.rb

Overview

Cyberweb::Objectified::HtmlTags::Img

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Cyberweb::Objectified::HtmlTags::Base

#+, #add_css_rules, #add_this_to_javascript, #add_to_pre_content, #append_css_manager, #append_onto_the_css_class, #append_onto_the_result, #append_the_content, #append_this_to_the_css_style, #attach, #batch_append_css_class_then_the_ID_and_then_the_css_style, #bblack1, #bblack2, #bblack3, #bblack4, #bblack5, #bblack6, #center, #consider_adding_the_pre_content, #consider_adding_the_script_entry_from_the_internal_hash, #content?, #content_as_string, #css_class?, #css_manager, #css_style?, #display, #do_not_load_lazily, #ee, #enable_lazy_loading, #evaluate_this_block, #font=, #id?, #is_an_objectified_html_tag?, #is_draggable?, #lazy_loading?, #make_bold, #modify_the_css_style_based_on_the_alignment, #name=, #name?, #on_click_select, #on_clicked, #on_hover_colour, #on_hover_pulse_increase, #on_mouse_hover, #pad, #pad10px, #pad1px, #pad2px, #pad3px, #pad4px, #pad5px, #pad6px, #pad7px, #pad8px, #pad9px, #path_to_internal_javascript_file, #pre_content?, #raw_result?, #report, report, #report?, #reset_the_content, #reset_the_result, #return_appendable_content, #return_css_class, #return_css_style, #return_javascript, #script?, #set_content, #set_css_class, #set_css_style, #set_id, #set_is_draggable, #set_title, #set_width, #title?, #to_str, #try_to_register_this_tag, #use_this_on_click_function=, #very_light_yellowish_background, #width_height, #yellow_background

Methods included from Cyberweb::BaseModule

#attach_these_constants, #base_dir?, #beautiful_url, #cd, #create_the_internal_hash, #doctype?, #ee, #ensure_main_encoding, #esystem, #html_templates, #initialize_the_config_if_the_config_hash_is_empty, #internal_hash?, #log_dir?, #no_http, #random_alphabet_characters, #rarrow?, #rds, #remove_comments_from_this_string, #remove_numbers, #require_the_html_templates, #require_these, #return_file_size_in_kb_of, #return_html_comment, #ruby_sitelib_dir?, #sanitize_this_id, #server_base_directory?, #string_remote_image, #today?, #try_to_require_rack, #try_to_require_the_open_gem, #write_what_into

Methods included from Cyberweb::BaseModule::ContentType

#content_type_is_html, #content_type_is_jpeg, #content_type_is_json, #content_type_is_plain_text

Methods included from Cyberweb::BaseModule::CommandlineArguments

#append_to_the_commandline_arguments, #commandline_arguments?, #first_argument?, #parse_these_commandline_arguments, #second_argument?, #set_commandline_arguments

Methods included from Cyberweb::BaseModule::Colours

#all_html_colours, #lightgreen, #rev, #sdir, #sfancy, #sfile, #simp, #steelblue, #tomato

Constructor Details

#initialize(use_this_text = '', optional_css_class = Img.css_class?, optional_id = nil, optional_css_style = nil, &block) ⇒ Img

#

initialize

Usage example:

Cyberweb::Objectified::HtmlTags::Img.new(i)
#


59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/cyberweb/objectified/html_tags/img.rb', line 59

def initialize(
    use_this_text      = '',
    optional_css_class = Img.css_class?,
    optional_id        = nil,
    optional_css_style = nil,
    &block
  )
  try_to_register_this_tag(self)
  reset
  use_this_text = use_this_text.join(' ').strip if use_this_text.is_a? Array
  set_content(use_this_text)
  set_CSS_class(optional_css_class) if optional_css_class
  set_id(optional_id)               if optional_id
  set_CSS_style(optional_css_style) if optional_css_style
  if block_given?
    evaluate_this_block(&block)
  end
end

Class Method Details

.clearObject

#

Cyberweb::Objectified::HtmlTags::Img.clear

#


33
34
35
# File 'lib/cyberweb/objectified/html_tags/img.rb', line 33

def self.clear
  Img.set_css_class('')
end

.css_class?Boolean

#

Cyberweb::Objectified::HtmlTags::Img.css_class?

#

Returns:

  • (Boolean)


47
48
49
# File 'lib/cyberweb/objectified/html_tags/img.rb', line 47

def self.css_class?
  @css_class
end

.reset_css_classObject

#

Cyberweb::Objectified::HtmlTags::Img.reset_css_class

#


26
27
28
# File 'lib/cyberweb/objectified/html_tags/img.rb', line 26

def self.reset_css_class
  @css_class = nil
end

.set_css_class(i = DEFAULT_CSS_CLASS) ⇒ Object

#

Cyberweb::Objectified::HtmlTags::Img.set_css_class

#


40
41
42
# File 'lib/cyberweb/objectified/html_tags/img.rb', line 40

def self.set_css_class(i = DEFAULT_CSS_CLASS)
  @css_class = i
end

Instance Method Details

#do_downloadObject Also known as: download

#

do_download

This will download the remote image.

#


94
95
96
97
98
99
100
101
102
# File 'lib/cyberweb/objectified/html_tags/img.rb', line 94

def do_download
  require 'cyberweb/toplevel_methods/toplevel_methods.rb'
  use_this_URL = content?
  if Cyberweb.log_dir?.nil?
    Cyberweb.initialize_the_configuration
  end
  cd(::Cyberweb.log_dir?)
  ::Cyberweb.download_webpage(use_this_URL)
end

#on_mouse_over(&block) ⇒ Object

#

on_mouse_over

Act on on-mouse-over events.

#


109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/cyberweb/objectified/html_tags/img.rb', line 109

def on_mouse_over(&block)
  # ======================================================================= #
  # Handle blocks given next:
  # ======================================================================= #
  if block_given?
    yielded = yield
    # ===================================================================== #
    # === Handle Hashes next:
    # ===================================================================== #
    if yielded.is_a? Hash
      # =================================================================== #
      # === :delay
      # =================================================================== #
      if yielded.has_key? :delay
        # ================================================================= #
        # We also have to add the appropriate CSS class:
        # ================================================================= #
        append_to_css_class 'transform_enlarge'
        pre_content? << '.transform_enlarge {
transform: scale(1);
transition: transform '+yielded[:delay].to_s+'s;
}
        '+"\n"
      end
      # =================================================================== #
      # === :upscale
      #
      # This is the hover-variant. Input may be like this:
      #
      #   upscale: '+10%'
      #
      # =================================================================== #
      if yielded.has_key? :upscale
        upscale_value = yielded[:upscale]
        if upscale_value.is_a? String
          if upscale_value.include? '%'
            upscale_value = upscale_value.delete('+%').to_f
            upscale_value = (100 + upscale_value) / 100.0
          end
        end
        pre_content? << '.transform_enlarge:hover {
transform: scale('+upscale_value.to_s+');
}

        '+"\n"
      end
    end
  end
end

#rebuild_the_resultObject

#

rebuild_the_result

#


162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/cyberweb/objectified/html_tags/img.rb', line 162

def rebuild_the_result
  reset_the_result
  pre_content = pre_content?.to_s
  if pre_content
    unless pre_content.to_s.empty?
      append_onto_the_result(
      '<style>
'+ # This peculiar line-wrap is fine, I think.
  pre_content.rstrip+'
</style>
')
    end
  end
  append_onto_the_result '<img'
  batch_append_css_class_then_the_ID_and_then_the_css_style
  content = content?
  if content and !content.to_s.empty?
    append_onto_the_result ' src="'+content.to_s+'"' unless content.to_s.empty?
  end
  # ========================================================================= #
  # Support lazy-loading next:
  # ========================================================================= #
  if lazy_loading?
    append_onto_the_result " loading=\"lazy\""
  end
  # ======================================================================= #
  # Next, close the <img> tag:
  # ======================================================================= #
  append_onto_the_result '>'
  append_onto_the_result "\n\n"
  # ======================================================================= #
  # <img> does not have a closing tag in HTML.
  # ======================================================================= #
  return raw_result?
end

#resetObject

#

reset

#


81
82
83
84
85
86
87
# File 'lib/cyberweb/objectified/html_tags/img.rb', line 81

def reset
  super()
  # ======================================================================= #
  # === :lazy_loading
  # ======================================================================= #
  do_not_load_lazily
end