Class: Qipowl::Bowlers::Html
- Defined in:
- lib/qipowl/bowlers/html.rb
Constant Summary
Constants inherited from Bowler
Instance Attribute Summary
Attributes inherited from Bowler
Instance Method Summary collapse
-
#closing(tag) ⇒ String
private
Constructs closing html tag for the input given.
-
#get_href_content(href) ⇒ Symbol
private
Determines content of remote link by href.
-
#opening(tag, params = {}) ⇒ String
private
Constructs opening html tag for the input given.
-
#orphan(str) ⇒ String
private
Produces html paragraph tag (
<p>) with classowl. -
#special_handler(method, *args, &block) ⇒ Array
private
Hence we cannot simply declare the DSL for it, we need to handle calls to all the methods, starting with those symbols.
-
#standalone(tag, params = {}) ⇒ String
private
Constructs opening html tag for the input given.
-
#tagify(tag, params, *args) ⇒ String
private
Constructs valid tag for the input given, concatenating opening and closing tags around the text passed in
args. -
#——(*args) ⇒ Nil
:alonehandler for horizontal rule; it differs from default handler since orphans around must be handled as well. -
#†(*args) ⇒ Array
Handler for abbrs.
-
#∀_alone(*args) ⇒ Array
:alonedefault handler. -
#∀_block(param, args) ⇒ Nil
:blockdefault handler opening tag. -
#∀_grip(*args) ⇒ Array
:gripdefault handler. -
#∀_magnet(*args) ⇒ Array
:magnetdefault handler. -
#∀_regular(*args) ⇒ Object
:regulardefault handler. -
#▶(*args) ⇒ Nil
(also: #▷)
:regularhandler for data lists (required since data list items consist of two tags:dtanddd.). - #☇(*args) ⇒ Object
-
#⚓(*args) ⇒ Array
Handler for anchors.
-
#⚘(*args) ⇒ Nil
Handler for standalone pictures and.
-
#✇(*args) ⇒ Nil
Handler for Youtube video.
-
#✍(*args) ⇒ Nil
:blockhandler for comment (required because comments are formatted in HTML in some specific way.). -
#✎(*args) ⇒ Nil
:magnethandler for reference to Livejournal user.
Methods inherited from Bowler
#add_entity, #block, const_missing, #custom, #execute, #grip, #method_missing, #remove_entity, #respond_to?, #split
Methods included from TypoLogging
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Qipowl::Bowlers::Bowler
Instance Method Details
#closing(tag) ⇒ String (private)
Constructs closing html tag for the input given.
276 277 278 |
# File 'lib/qipowl/bowlers/html.rb', line 276 def closing tag "</#{tag}>" end |
#get_href_content(href) ⇒ Symbol (private)
Determines content of remote link by href. TODO Make image patterns configurable.
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 |
# File 'lib/qipowl/bowlers/html.rb', line 303 def get_href_content href href = href.to_s.unbowl.strip if href.end_with?(* %w{png jpg jpeg gif PNG JPG JPEG GIF}) :img elsif /\/\/i\.chzbgr/ =~ href :img else :text end # uri = URI(href.to_s.unbowl) # Net::HTTP.start(uri.host, uri.port) do |http| # http.open_timeout = 1 # http.read_timeout = 1 # # request = Net::HTTP::Head.new uri # response = http.request request # case response.to_hash["content-type"].first # when /image/ then return :img # when /text/ then return :text # end # end # :unknown #rescue # logger.warn "Unable to determine link [#{href.to_s.unbowl}] type: no internet connection. Reverting to default." # :unknown end |
#opening(tag, params = {}) ⇒ String (private)
Constructs opening html tag for the input given.
To construct abbr tag with title Title and class default:
opening :abbr, { :title=>'Title', :class=>'default' }
267 268 269 270 |
# File 'lib/qipowl/bowlers/html.rb', line 267 def opening tag, params={} attrs = params.inject("") { |m, el| m.prepend " #{el.first}='#{el.last}'" unless el.last.nil? ; m } "<#{tag}#{attrs}>" end |
#orphan(str) ⇒ String (private)
Produces html paragraph tag (<p>) with class owl.
255 256 257 |
# File 'lib/qipowl/bowlers/html.rb', line 255 def orphan str "#{tagify(:p, {}, str.to_s.strip)}" end |
#special_handler(method, *args, &block) ⇒ Array (private)
Hence we cannot simply declare the DSL for it, we need to handle calls to all the methods, starting with those symbols.
242 243 244 245 246 247 248 249 |
# File 'lib/qipowl/bowlers/html.rb', line 242 def special_handler method, *args, &block # Sublevel markers, e.g. “ •” is level 2 line-item return [method, args].flatten \ unless level(method) > 0 && self.class::REGULAR_TAGS.keys.include?(canonize(method)) self.class.class_eval "alias_method :#{method}, :#{canonize(method)}" send method, args, block end |
#standalone(tag, params = {}) ⇒ String (private)
Constructs opening html tag for the input given.
To construct abbr tag with title Title and class default:
opening :abbr, { :title=>'Title', :class=>'default' }
Acts most like an #opening method, but closes an element inplace
(used for hr, br, img).
283 284 285 |
# File 'lib/qipowl/bowlers/html.rb', line 283 def standalone tag, params={} opening(tag, params).sub('>', '/>') end |
#tagify(tag, params, *args) ⇒ String (private)
Constructs valid tag for the input given, concatenating
opening and closing tags around the text passed in args.
293 294 295 296 |
# File 'lib/qipowl/bowlers/html.rb', line 293 def tagify tag, params, *args text = [*args].join(SEPARATOR) text.vacant? ? '' : "#{opening tag, params}#{text}#{closing tag}" end |
#——(*args) ⇒ Nil
:alone handler for horizontal rule; it differs from default
handler since orphans around must be handled as well.
103 104 105 106 |
# File 'lib/qipowl/bowlers/html.rb', line 103 def |
#†(*args) ⇒ Array
Handler for abbrs.
73 74 75 76 77 |
# File 'lib/qipowl/bowlers/html.rb', line 73 def |
#∀_alone(*args) ⇒ Array
:alone default handler
29 30 31 |
# File 'lib/qipowl/bowlers/html.rb', line 29 def |
#∀_block(param, args) ⇒ Nil
:block default handler
opening tag
38 39 40 41 42 43 44 45 |
# File 'lib/qipowl/bowlers/html.rb', line 38 def |
#∀_grip(*args) ⇒ Array
:grip default handler
20 21 22 23 24 |
# File 'lib/qipowl/bowlers/html.rb', line 20 def |
#∀_magnet(*args) ⇒ Array
:magnet default handler
50 51 52 53 54 |
# File 'lib/qipowl/bowlers/html.rb', line 50 def |
#∀_regular(*args) ⇒ Object
:regular default handler
58 59 60 61 62 63 64 65 |
# File 'lib/qipowl/bowlers/html.rb', line 58 def |
#▶(*args) ⇒ Nil Also known as: ▷
:regular handler for data lists (required since data list items
consist of two tags: dt and dd.)
177 178 179 180 181 182 183 |
# File 'lib/qipowl/bowlers/html.rb', line 177 def |
#☇(*args) ⇒ Object
134 135 136 137 |
# File 'lib/qipowl/bowlers/html.rb', line 134 def |
#⚓(*args) ⇒ Array
Handler for anchors.
82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/qipowl/bowlers/html.rb', line 82 def |
#⚘(*args) ⇒ Nil
Make it to understand quotes when there is a plain HTML on the other side
Handler for standalone pictures and
159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/qipowl/bowlers/html.rb', line 159 def |
#✇(*args) ⇒ Nil
Handler for Youtube video
145 146 147 148 149 150 151 152 |
# File 'lib/qipowl/bowlers/html.rb', line 145 def |
#✍(*args) ⇒ Nil
:block handler for comment (required because comments are
formatted in HTML in some specific way.)
116 117 118 |
# File 'lib/qipowl/bowlers/html.rb', line 116 def |
#✎(*args) ⇒ Nil
:magnet handler for reference to Livejournal user.
127 128 129 130 131 132 |
# File 'lib/qipowl/bowlers/html.rb', line 127 def |