Module: Redcarpet::Form::Extension::Util
- Defined in:
- lib/redcarpet/form/extension/util.rb
Overview
Utils
Class Method Summary collapse
- .attributes_pattern ⇒ Object
- .attributes_to_s(attributes) ⇒ Object
- .parse_attributes(text) ⇒ Object
- .random_string ⇒ Object
Class Method Details
.attributes_pattern ⇒ Object
8 9 10 |
# File 'lib/redcarpet/form/extension/util.rb', line 8 def self.attributes_pattern /(\S+)=["']([^"']*)["']/ end |
.attributes_to_s(attributes) ⇒ Object
23 24 25 26 27 |
# File 'lib/redcarpet/form/extension/util.rb', line 23 def self.attributes_to_s(attributes) return '' unless attributes attributes.map { |k, v| "#{k}=\"#{v}\"" }.join(' ') end |
.parse_attributes(text) ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/redcarpet/form/extension/util.rb', line 12 def self.parse_attributes(text) return {} unless text attr_str = text.match(/[{]([^}]*)/) return {} unless attr_str return {} unless attr_str[1] attr_str[1].scan(attributes_pattern).to_h end |
.random_string ⇒ Object
29 30 31 |
# File 'lib/redcarpet/form/extension/util.rb', line 29 def self.random_string (0...6).map { ('a'..'z').to_a[rand(26)] }.join end |