Class: Hashtags::Base
- Inherits:
-
Struct
- Object
- Struct
- Hashtags::Base
- Defined in:
- lib/hashtags/base.rb
Overview
Base class, from which all Hashtag types inherit In case you wish to add a new type next to • ResourceType • Resource • User • Variable you might want to inherit from Base.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#str ⇒ Object
Returns the value of attribute str.
Class Method Summary collapse
-
.cache_key ⇒ Object
used to expire field with tags.
- .descendants ⇒ Object
-
.help_values ⇒ Object
implement to show which values particular trigger offers fe # -> lists all available resource types.
-
.json_for_query(query) ⇒ Object
return JSON version of resources that match query this is returned when user starts typing (the query).
-
.json_regexp(regexp) ⇒ Object
converts Ruby tegexp to JS regexp.
-
.match_index ⇒ Object
index of the match group from the above regexp to be used for matching.
-
.match_regexp ⇒ Object
trigger dropdown when user input matches this regexp.
-
.match_template ⇒ Object
matched against as user types typically this would equal to the .template (match what you see).
-
.path ⇒ Object
implement to use custom controller.
-
.regexp ⇒ Object
regexp to recognize the complete tag.
-
.replace ⇒ Object
tag that gets inserted into the field.
- .resource_classes ⇒ Object
-
.strategy(hashtag_classes) ⇒ Object
to be passed to textcomplete.
-
.template ⇒ Object
fragment to be displayed in the dropdown menu.
- .to_hashtag(str) ⇒ Object
- .to_markup(str) ⇒ Object
-
.trigger ⇒ Object
for example @ # $ ….
- .user_classes ⇒ Object
-
.values(hashtag_classes = Variable.descendants) ⇒ Object
implement to preload hash tag values, fe in case there is limited number (ie variable names).
- .variable_classes ⇒ Object
Instance Method Summary collapse
-
#hashtag(match) ⇒ Object
the proper hashtag (so it can be updated automatically).
-
#markup(match) ⇒ Object
what is the hashtag replaced with in the end.
-
#to_hashtag ⇒ Object
Updates hash tags.
-
#to_markup ⇒ Object
Converts hash tags to markup.
Instance Attribute Details
#str ⇒ Object
Returns the value of attribute str
10 11 12 |
# File 'lib/hashtags/base.rb', line 10 def str @str end |
Class Method Details
.cache_key ⇒ Object
used to expire field with tags
61 62 63 |
# File 'lib/hashtags/base.rb', line 61 def self.cache_key raise NotImplementedError end |
.descendants ⇒ Object
19 20 21 |
# File 'lib/hashtags/base.rb', line 19 def self.descendants ObjectSpace.each_object(Class).select { |klass| klass < self } end |
.help_values ⇒ Object
implement to show which values particular trigger offers fe # -> lists all available resource types
81 82 |
# File 'lib/hashtags/base.rb', line 81 def self.help_values end |
.json_for_query(query) ⇒ Object
return JSON version of resources that match query this is returned when user starts typing (the query)
111 112 113 |
# File 'lib/hashtags/base.rb', line 111 def self.json_for_query(query) raise NotImplementedError end |
.json_regexp(regexp) ⇒ Object
converts Ruby tegexp to JS regexp
121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/hashtags/base.rb', line 121 def self.json_regexp(regexp) str = regexp.inspect .sub('\\A', '^') .sub('\\Z', '$') .sub('\\z', '$') .sub(/^\//, '') .sub(/\/[a-z]*$/, '') .gsub(/\(\?#.+\)/, '') .gsub(/\(\?-\w+:/, '(') .gsub(/\s/, '') Regexp.new(str).source end |
.match_index ⇒ Object
index of the match group from the above regexp to be used for matching
93 94 95 |
# File 'lib/hashtags/base.rb', line 93 def self.match_index raise NotImplementedError end |
.match_regexp ⇒ Object
trigger dropdown when user input matches this regexp
88 89 90 |
# File 'lib/hashtags/base.rb', line 88 def self.match_regexp raise NotImplementedError end |
.match_template ⇒ Object
matched against as user types typically this would equal to the .template (match what you see)
56 57 58 |
# File 'lib/hashtags/base.rb', line 56 def self.match_template template end |
.path ⇒ Object
implement to use custom controller
71 72 |
# File 'lib/hashtags/base.rb', line 71 def self.path end |
.regexp ⇒ Object
regexp to recognize the complete tag
66 67 68 |
# File 'lib/hashtags/base.rb', line 66 def self.regexp raise NotImplementedError end |
.replace ⇒ Object
tag that gets inserted into the field
98 99 100 |
# File 'lib/hashtags/base.rb', line 98 def self.replace raise NotImplementedError end |
.resource_classes ⇒ Object
23 24 25 |
# File 'lib/hashtags/base.rb', line 23 def self.resource_classes Resource.descendants end |
.strategy(hashtag_classes) ⇒ Object
to be passed to textcomplete
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/hashtags/base.rb', line 36 def self.strategy(hashtag_classes) { class_name: to_s, match_regexp: json_regexp(match_regexp), match_index: match_index, match_template: match_template, path: path, replace: replace, template: template, values: values(hashtag_classes) } end |
.template ⇒ Object
fragment to be displayed in the dropdown menu
103 104 105 |
# File 'lib/hashtags/base.rb', line 103 def self.template raise NotImplementedError end |
.to_hashtag(str) ⇒ Object
15 16 17 |
# File 'lib/hashtags/base.rb', line 15 def self.to_hashtag(str) new(str).to_hashtag end |
.to_markup(str) ⇒ Object
11 12 13 |
# File 'lib/hashtags/base.rb', line 11 def self.to_markup(str) new(str).to_markup end |
.trigger ⇒ Object
for example @ # $ …
50 51 52 |
# File 'lib/hashtags/base.rb', line 50 def self.trigger raise NotImplementedError end |
.user_classes ⇒ Object
27 28 29 |
# File 'lib/hashtags/base.rb', line 27 def self.user_classes User.descendants end |
.values(hashtag_classes = Variable.descendants) ⇒ Object
implement to preload hash tag values, fe in case there is limited number (ie variable names)
76 77 |
# File 'lib/hashtags/base.rb', line 76 def self.values(hashtag_classes) end |
.variable_classes ⇒ Object
31 32 33 |
# File 'lib/hashtags/base.rb', line 31 def self.variable_classes Variable.descendants end |
Instance Method Details
#hashtag(match) ⇒ Object
the proper hashtag (so it can be updated automatically)
155 156 157 |
# File 'lib/hashtags/base.rb', line 155 def hashtag(match) raise NotImplementedError end |
#markup(match) ⇒ Object
what is the hashtag replaced with in the end
160 161 162 |
# File 'lib/hashtags/base.rb', line 160 def markup(match) raise NotImplementedError end |
#to_hashtag ⇒ Object
Updates hash tags
145 146 147 148 149 150 |
# File 'lib/hashtags/base.rb', line 145 def to_hashtag str.to_s.gsub(self.class.regexp) do |match| ht = hashtag(Regexp.last_match) match = ht || match end end |
#to_markup ⇒ Object
Converts hash tags to markup
137 138 139 140 141 142 |
# File 'lib/hashtags/base.rb', line 137 def to_markup str.to_s.gsub(self.class.regexp) do |match| m = markup(Regexp.last_match) match = m || match end end |