hashtags 0.1.2 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0cb6c025ac00ec488f3606c30d1fe1bc52864deb
4
- data.tar.gz: 8c80d45a0d2a58264217b57a83c5cb051116f8b0
3
+ metadata.gz: 3398fdce12caeb726d4adc16b28b799ccd9ed5db
4
+ data.tar.gz: ce30097b9e991abaad5afe8e7753bba7d0bc6604
5
5
  SHA512:
6
- metadata.gz: bd6389a9708ec563fd32338872fa6151c5474a42ddad99fd5789ee743a7bfd2aa107c5ee42700f182e269d2700acde97a42678c8574efd843746c808666a466c
7
- data.tar.gz: f5ce031172ef994e4f431905c1a41f71ca15f0b82ade9a74b477f364d5782b934c656f31dec58874e3ff4b1972fb544af378560a98d4d48183b4ee09572ce961
6
+ metadata.gz: 73b1538ba00e4032592226e93565858244fb9c13107e1b29318cc5b010ddea1efcd9fafccf46aa8c9dec7065cd1734d40a787df8fdcaa416fd57156cf3448195
7
+ data.tar.gz: a12ceef70226d683696d1669f12a83438b23da3998180460297089ff9c7e1d1f90b60e75f1e9ba1b68bca8ee69a2eee1ea2b4f31e0dd29a67db1fdeff69757c3
@@ -0,0 +1,7 @@
1
+ # CHANGELOG
2
+
3
+ ## 0.2.2
4
+
5
+ * refactor to avoid conflicts between classes
6
+ * `render_help_for` renamed to `render_hashtags_help_for`
7
+ * add `hashtags` class to the `dropdownClassName` option
data/README.md CHANGED
@@ -142,7 +142,7 @@ Implement the `values` class method instead of the `resources_for_query` to prel
142
142
  See `Hashtags::Variable` and override its methods on your subclass as necessary. Typically it would be at least the following:
143
143
 
144
144
  ```ruby
145
- class VariableTag < Hashtags::Resource
145
+ class VariableTag < Hashtags::Variable
146
146
  def self.values(hashtag_classes = Hashtags::Variable.descendants)
147
147
  # %w(
148
148
  # variable_1
@@ -235,7 +235,7 @@ In a form:
235
235
  ```slim
236
236
  fieldset
237
237
  = form.text_area :text, data: form.object.class.hashtags['text'].dom_data
238
- = render_help_for(form.object.class, :text)
238
+ = render_hashtags_help_for(form.object.class, :text)
239
239
  ```
240
240
 
241
241
  ## Development
@@ -1,6 +1,6 @@
1
1
  module Hashtags
2
2
  module ViewHelper
3
- def render_help_for(cls, field_name)
3
+ def render_hashtags_help_for(cls, field_name)
4
4
  return unless help = cls.hashtags[field_name.to_s].help
5
5
  render 'hashtags/help', help: help
6
6
  end
@@ -21,7 +21,12 @@
21
21
  @init()
22
22
 
23
23
  init: ->
24
- @$element.textcomplete(@get_strategies())
24
+ @$element.textcomplete(
25
+ @get_strategies(),
26
+ {
27
+ dropdownClassName: 'hashtags dropdown-menu textcomplete-dropdown'
28
+ }
29
+ )
25
30
 
26
31
  get_data: -> @$element.data 'hashtags'
27
32
  get_default_path: -> @get_data()['path']
@@ -1,4 +1,4 @@
1
- ul.textcomplete-dropdown {
1
+ ul.hashtags.textcomplete-dropdown {
2
2
  background-color: white;
3
3
  border: 1px solid;
4
4
  list-style: none;
@@ -51,7 +51,10 @@ module Hashtags
51
51
  raise NotImplementedError
52
52
  end
53
53
 
54
+ # matched against as user types
55
+ # typically this would equal to the .template (match what you see)
54
56
  def self.match_template
57
+ template
55
58
  end
56
59
 
57
60
  # used to expire field with tags
@@ -3,38 +3,41 @@ require 'ostruct'
3
3
 
4
4
  Mongoid::Fields.option :hashtags do |cls, field, value|
5
5
  return if value == false
6
+ return if cls.respond_to?(:hashtags)
6
7
 
7
- cls.define_singleton_method(:hashtags) { @hashtags ||= {} } unless cls.respond_to?(:hashtags)
8
- options = value.is_a?(Hash) ? value.slice(*%i(only except)) : {}
8
+ cls.define_singleton_method :hashtags do
9
+ options = (value.is_a?(Hash) ? value.slice(*%i(only except)) : {})
9
10
 
10
- cls.hashtags[field.name].define_singleton_method :dom_data do
11
- Hashtags::Builder.dom_data(options)
12
- end
13
-
14
- cls.hashtags[field.name].define_singleton_method :help do
15
- Hashtags::Builder.help(options)
16
- end
17
-
18
- cls.hashtags[field.name].define_singleton_method :options do
19
- options
11
+ @hashtags ||= {}
12
+ @hashtags[field.name] ||= OpenStruct.new(
13
+ dom_data: Hashtags::Builder.dom_data(options),
14
+ help: Hashtags::Builder.help(options),
15
+ options: options
16
+ )
17
+ @hashtags
20
18
  end
21
19
 
22
20
  field.define_singleton_method :demongoize do |*args|
23
21
  res = super(*args)
22
+
24
23
  res.define_singleton_method :to_markup do
25
- field.type.new(
26
- Hashtags::Builder.to_markup(res.to_s, options).html_safe
27
- )
24
+ ho = field.options[:hashtags]
25
+ options = (ho.is_a?(Hash) ? ho.slice(*%i(only except)) : {})
26
+ field.type.new(Hashtags::Builder.to_markup(res.to_s, options).html_safe)
28
27
  end
28
+
29
29
  res.define_singleton_method :to_hashtag do
30
- field.type.new(
31
- Hashtags::Builder.to_hashtag(res.to_s, options).html_safe
32
- )
30
+ ho = field.options[:hashtags]
31
+ options = (ho.is_a?(Hash) ? ho.slice(*%i(only except)) : {})
32
+ field.type.new(Hashtags::Builder.to_hashtag(res.to_s, options).html_safe)
33
33
  end
34
+
34
35
  res
35
36
  end
36
37
 
37
- field.define_singleton_method :mongoize do |value|
38
- Hashtags::Builder.to_hashtag(super(value.to_s), options)
38
+ field.define_singleton_method :mongoize do |val|
39
+ ho = field.options[:hashtags]
40
+ options = (ho.is_a?(Hash) ? ho.slice(*%i(only except)) : {})
41
+ Hashtags::Builder.to_hashtag(super(val.to_s), options)
39
42
  end
40
43
  end
@@ -55,10 +55,6 @@ module Hashtags
55
55
  2
56
56
  end
57
57
 
58
- def self.match_template
59
- "{{ #{tag_attribute} }}"
60
- end
61
-
62
58
  def self.replace
63
59
  "#{trigger}#{resource_name}:{{ #{tag_attribute} }}({{ id }})"
64
60
  end
@@ -18,7 +18,7 @@ module Hashtags
18
18
  # JS
19
19
 
20
20
  def self.match_regexp
21
- /(\A#{trigger}|\s#{trigger})(\w*)\z/
21
+ /(#{trigger})(\w*)\z/
22
22
  end
23
23
 
24
24
  def self.match_index
@@ -44,17 +44,13 @@ module Hashtags
44
44
  # JS
45
45
 
46
46
  def self.match_regexp
47
- /(\A#{Regexp.escape(trigger)}|\s#{Regexp.escape(trigger)})(\w{1,})\z/
47
+ /(#{Regexp.escape(trigger)})(\w{1,})\z/
48
48
  end
49
49
 
50
50
  def self.match_index
51
51
  2
52
52
  end
53
53
 
54
- def self.match_template
55
- "{{ #{tag_attribute} }}"
56
- end
57
-
58
54
  def self.replace
59
55
  "#{trigger}{{ #{tag_attribute} }}"
60
56
  end
@@ -20,7 +20,7 @@ module Hashtags
20
20
  # JS
21
21
 
22
22
  def self.match_regexp
23
- /(\A#{Regexp.escape(trigger)}|\s#{Regexp.escape(trigger)})(\w{1,})\z/
23
+ /(#{Regexp.escape(trigger)})(\w{1,})\z/
24
24
  end
25
25
 
26
26
  def self.match_index
@@ -1,3 +1,3 @@
1
1
  module Hashtags
2
- VERSION = '0.1.2'.freeze
2
+ VERSION = '0.2.2'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hashtags
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomas Celizna
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-11-24 00:00:00.000000000 Z
11
+ date: 2017-05-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: handlebars
@@ -187,6 +187,7 @@ extra_rdoc_files: []
187
187
  files:
188
188
  - ".gitignore"
189
189
  - ".travis.yml"
190
+ - CHANGELOG.md
190
191
  - Gemfile
191
192
  - Guardfile
192
193
  - LICENSE.txt
@@ -236,7 +237,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
236
237
  version: '0'
237
238
  requirements: []
238
239
  rubyforge_project:
239
- rubygems_version: 2.4.5.1
240
+ rubygems_version: 2.5.2
240
241
  signing_key:
241
242
  specification_version: 4
242
243
  summary: Rails engine to facilitate inline text hashtags.