ubbparser 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/lib/ubbparser.rb +12 -5
  2. metadata +2 -2
@@ -26,6 +26,13 @@ require "cgi"
26
26
 
27
27
  module UBBParser
28
28
 
29
+ # Mapping can be used to allow simplified use of files
30
+ # [img]123123[/img] would have the same effect as [img]files/download/123123[/img]
31
+ #noinspection RubyClassVariableUsageInspection
32
+ def self.set_file_url_convert_method(callback_method)
33
+ @@file_url_convert_method = callback_method
34
+ end
35
+
29
36
  # Converts a strings containing key-value-list into a hash. This function is mostly used by the parser itself.
30
37
  # Attributes are given to the render methods as a hash.
31
38
  def self.attrib_str_to_hash(attrib_str)
@@ -122,8 +129,6 @@ module UBBParser
122
129
  return self.matches_regexp?(value, /^(http|https)\:\/\/([a-zA-Z0-9\.\-]+(\:[a-zA-Z0-9\.&%\$\-]+)*@)*((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])|localhost|([a-zA-Z0-9\-]+\.)*[a-zA-Z0-9\-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(\:[0-9]+)*(\/($|[a-zA-Z0-9\.\,\?\'\\\+&%\$#\=~_\-]+))*$/)
123
130
  end
124
131
 
125
-
126
-
127
132
  # Converts the [anchor=myname]...[/anchor] tag into <a name='myname'>...</a>. Use the :class_anchor parse option to define html classes.
128
133
  # :category: Render methods
129
134
  def self.render_anchor(inner_text, attributes = {}, parse_options = {})
@@ -305,10 +310,11 @@ module UBBParser
305
310
 
306
311
  # Renders an image. Use the :class_img parse option to define html classes.
307
312
  # :category: Render methods
313
+ #noinspection RubyClassVariableUsageInspection
308
314
  def self.render_img(inner_text, attributes = {}, parse_options = {})
309
315
  url = inner_text
310
- url = "" if (!self.is_url?(inner_text))
311
- attributes[:src] = inner_text.gsub(/\\|'/) { |c| "\\#{c}" }
316
+ url = @@file_url_convert_method.call(url) unless @@file_url_convert_method.nil?
317
+ attributes[:src] = url.gsub(/\\|'/) { |c| "\\#{c}" }
312
318
  attributes[:alt] ||= ""
313
319
  attributes[:class] = parse_options[:class_img] if ((!attributes.has_key?(:skip_class)) || !attributes[:skip_class])
314
320
  attrib_str = self.hash_to_attrib_str(attributes, :allowed_keys => [:src, :alt, :styles, :class])
@@ -413,7 +419,8 @@ module UBBParser
413
419
  def self.render_url(inner_text, attributes = {}, parse_options = {})
414
420
  url = (attributes[:default] || inner_text)
415
421
  url = "http://" + url if (url.match(/^www\./))
416
- url.gsub!(/\\|'/) { |c| "\\#{c}" }
422
+ url = @@file_url_convert_method.call(url) unless @@file_url_convert_method.nil?
423
+ url.gsub!(/\\|'/) { |c| "\\#{c}" }
417
424
  return "<a href='#{url}' class='#{parse_options[:class_url].to_s.strip}'>#{inner_text}</a>"
418
425
  end
419
426
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ubbparser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-13 00:00:00.000000000 Z
12
+ date: 2013-07-04 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A simple and flexibel ubb parser.
15
15
  email: info@osingasoftware.nl