Class: Smiley
- Inherits:
-
Object
- Object
- Smiley
- Defined in:
- lib/smiley.rb
Constant Summary collapse
- VALID_CSS_CLASS_STYLES =
[:dashed, :snake_case, :camel_case]
Class Method Summary collapse
- .all_class ⇒ Object
- .all_class=(klass) ⇒ Object
- .css_class_style ⇒ Object
- .css_class_style=(style) ⇒ Object
- .each_class_prefix ⇒ Object
- .each_class_prefix=(klass) ⇒ Object
- .smiley_file ⇒ Object
- .smiley_file=(file) ⇒ Object
Instance Method Summary collapse
Class Method Details
.all_class ⇒ Object
6 7 8 |
# File 'lib/smiley.rb', line 6 def self.all_class defined?(@@all_class) ? @@all_class : 'smiley' end |
.all_class=(klass) ⇒ Object
10 11 12 |
# File 'lib/smiley.rb', line 10 def self.all_class=(klass) @@all_class = klass end |
.css_class_style ⇒ Object
26 27 28 |
# File 'lib/smiley.rb', line 26 def self.css_class_style defined?(@@css_class_style) ? @@css_class_style : :dashed end |
.css_class_style=(style) ⇒ Object
30 31 32 33 34 35 |
# File 'lib/smiley.rb', line 30 def self.css_class_style=(style) unless VALID_CSS_CLASS_STYLES.include?(style.to_sym) raise "Invalid css class style #{style}. You can choose between :dashed, :snake_case and :camel_case" end @@css_class_style = style.to_sym end |
.each_class_prefix ⇒ Object
14 15 16 |
# File 'lib/smiley.rb', line 14 def self.each_class_prefix defined?(@@each_class_prefix) ? @@each_class_prefix : 'smiley' end |
.each_class_prefix=(klass) ⇒ Object
18 19 20 |
# File 'lib/smiley.rb', line 18 def self.each_class_prefix=(klass) @@each_class_prefix = klass end |
.smiley_file ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/smiley.rb', line 37 def self.smiley_file if defined?(@@smiley_file) return @@smiley_file elsif defined?(Rails) && Rails.respond_to?(:root) return File.join(Rails.root, 'config', 'smileys.yml') end end |
.smiley_file=(file) ⇒ Object
22 23 24 |
# File 'lib/smiley.rb', line 22 def self.smiley_file=(file) @@smiley_file = file end |
Instance Method Details
#parse(text) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/smiley.rb', line 45 def parse(text) text = h(text).gsub(self.class.regex) do %(<em class="#{css_class(self.class.smileys[$1])}"></em>) end text.respond_to?(:html_safe) ? text.html_safe : text end |