Module: Zwite::Utils
- Defined in:
- lib/zwite/core/utils.rb
Class Method Summary collapse
- .markdownify(str) ⇒ Object
- .parse_date_and_slug(str) {|date, slug| ... } ⇒ Object
- .parse_metadata_and_markdown(str) {|metadata, markdown| ... } ⇒ Object
Class Method Details
.markdownify(str) ⇒ Object
5 6 7 |
# File 'lib/zwite/core/utils.rb', line 5 def self.markdownify(str) return RDiscount.new(str, :smart).to_html end |
.parse_date_and_slug(str) {|date, slug| ... } ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/zwite/core/utils.rb', line 9 def self.parse_date_and_slug(str) regex = /^(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})-(?<hour>\d{2})(?<minute>\d{2})-(?<slug>.+)$/ matches = regex.match(str) if matches.nil? raise Exception::exception("error parsing date and slug #{str}") end date = DateTime.new(matches["year"].to_i, matches["month"].to_i, matches["day"].to_i, matches["hour"].to_i, matches["minute"].to_i, 0, DateTime.now.offset) slug = matches["slug"] yield date, slug end |
.parse_metadata_and_markdown(str) {|metadata, markdown| ... } ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/zwite/core/utils.rb', line 22 def self.(str) = nil markdown = nil if str =~ /^(---\s*\n.*?\n?)^(---\s*$\n?)/m markdown = markdownify($') unless $1.nil? yaml_contents = $1.gsub(/\t/, " ") unless yaml_contents.nil? = YAML.load(yaml_contents) end end end yield , markdown end |