Class: Asuka::Formatter
- Inherits:
-
Object
- Object
- Asuka::Formatter
- Defined in:
- lib/asuka/formatter.rb
Instance Method Summary collapse
- #bold(line) ⇒ Object
- #default_steps ⇒ Object
- #italic(line) ⇒ Object
-
#make_link(text, href, tags = {}) ⇒ Object
helper.
- #named_link(line) ⇒ Object
Instance Method Details
#bold(line) ⇒ Object
9 10 11 |
# File 'lib/asuka/formatter.rb', line 9 def bold(line) line.gsub(/\*\*([^*]+)\*\*/, '<strong>\1</strong>') end |
#default_steps ⇒ Object
5 6 7 |
# File 'lib/asuka/formatter.rb', line 5 def default_steps [:bold, :italic, :named_link] end |
#italic(line) ⇒ Object
13 14 15 |
# File 'lib/asuka/formatter.rb', line 13 def italic(line) line.gsub(/\*([^*]+)\*/, '<em>\1</em>') end |
#make_link(text, href, tags = {}) ⇒ Object
helper
18 19 20 21 22 23 24 |
# File 'lib/asuka/formatter.rb', line 18 def make_link(text, href, ={}) = .merge(:href => href.strip) = .sort_by { |name, value| name.to_s }. map { |name, value| %Q{ #{name}="#{value}"} } "<a#{}>#{text.strip}</a>" end |
#named_link(line) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/asuka/formatter.rb', line 26 def named_link(line) # up to ] (spaces allowed) up_to = /[^\]]+?/ brackets_without_http = /\[(#{up_to})\]/ # up to ] (spaces NOT allowed) up_to = /[^\]\s]+/ brackets_with_http = /\[\s*(https?:\/\/#{up_to})\s*\]/ line.gsub(/#{brackets_without_http}#{brackets_with_http}/) { |match| make_link($1, $2) }. gsub(/#{brackets_with_http}#{brackets_without_http}/) { |match| make_link($2, $1) } end |