enchanted_quill 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/enchanted_quill/element_creator.rb +6 -6
- data/lib/enchanted_quill/label.rb +86 -9
- data/lib/enchanted_quill/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3e82c15520eb37dad77de33e4bc2c73aca9d7855
|
|
4
|
+
data.tar.gz: 38318ca27d68557f57e53952a0995a993e5a6b5d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5d47b6625a959651a9a7cd06fb6d345431ac57c7e9648b4eb478a030c019d4532ab981c8e705682f6ae4ddc867193677ff29fcd5578c1522a58b5388147c2643
|
|
7
|
+
data.tar.gz: 32438a3e4f8169319164a3b0e766143989c5002c35f2073d0469d683d87fed511c047636d79890afe11caef688a12acad69738ec1ed07b0eb955d1bda0095725
|
|
@@ -8,8 +8,8 @@ module EnchantedQuill
|
|
|
8
8
|
|
|
9
9
|
mentions.each do |mention|
|
|
10
10
|
if mention.range.length > 2
|
|
11
|
-
range = NSMakeRange(mention.range.location
|
|
12
|
-
word = text.substringWithRange(range)
|
|
11
|
+
range = NSMakeRange(mention.range.location, mention.range.length)
|
|
12
|
+
word = text.substringWithRange(range).strip
|
|
13
13
|
|
|
14
14
|
if word[0] == '@'
|
|
15
15
|
word = word[1..-1]
|
|
@@ -28,8 +28,8 @@ module EnchantedQuill
|
|
|
28
28
|
|
|
29
29
|
hashtags.each do |hashtag|
|
|
30
30
|
if hashtag.range.length > 2
|
|
31
|
-
range = NSMakeRange(hashtag.range.location
|
|
32
|
-
word = text.substringWithRange(range)
|
|
31
|
+
range = NSMakeRange(hashtag.range.location, hashtag.range.length)
|
|
32
|
+
word = text.substringWithRange(range).strip
|
|
33
33
|
|
|
34
34
|
if word[0] == '#'
|
|
35
35
|
word = word[1..-1]
|
|
@@ -48,8 +48,8 @@ module EnchantedQuill
|
|
|
48
48
|
|
|
49
49
|
categories.each do |category|
|
|
50
50
|
if category.range.length > 2
|
|
51
|
-
range = NSMakeRange(category.range.location
|
|
52
|
-
word = text.substringWithRange(range)
|
|
51
|
+
range = NSMakeRange(category.range.location, category.range.length)
|
|
52
|
+
word = text.substringWithRange(range).strip
|
|
53
53
|
|
|
54
54
|
if word[0] == '{' && word[-1] == '}'
|
|
55
55
|
word = word[1..-2]
|
|
@@ -28,6 +28,65 @@ module EnchantedQuill
|
|
|
28
28
|
layout_manager.drawGlyphsForGlyphRange(range, atPoint: new_origin)
|
|
29
29
|
end
|
|
30
30
|
|
|
31
|
+
def layoutSubviews
|
|
32
|
+
super
|
|
33
|
+
text_container.size = self.bounds.size
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def setPreferredMaxLayoutWidth(preferred_max_layout_width)
|
|
37
|
+
super
|
|
38
|
+
update_text_container_size(self.bounds.size)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def setFrame(frame)
|
|
42
|
+
super
|
|
43
|
+
update_text_container_size(frame.size)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def setBounds(bounds)
|
|
47
|
+
super
|
|
48
|
+
update_text_container_size(bounds.size)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def update_text_container_size(size)
|
|
52
|
+
container_size = size
|
|
53
|
+
width = [size.width, self.preferredMaxLayoutWidth].min
|
|
54
|
+
height = 0
|
|
55
|
+
text_container.size = CGSizeMake(width, height)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
# Override UILabel Methods
|
|
60
|
+
def textRectForBounds(bounds, limitedToNumberOfLines: num_of_lines)
|
|
61
|
+
required_rect = rect_fitting_text_for_container_size(bounds.size, for_number_of_line: num_of_lines)
|
|
62
|
+
text_container.size = required_rect.size
|
|
63
|
+
required_rect
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def rect_fitting_text_for_container_size(size, for_number_of_line: num_of_lines)
|
|
67
|
+
text_container.size = size;
|
|
68
|
+
text_container.maximumNumberOfLines = num_of_lines
|
|
69
|
+
text_bounds = layout_manager.boundingRectForGlyphRange(NSMakeRange(0, layout_manager.numberOfGlyphs),
|
|
70
|
+
inTextContainer: text_container)
|
|
71
|
+
total_lines = text_bounds.size.height / self.font.lineHeight
|
|
72
|
+
|
|
73
|
+
height = text_bounds.size.height
|
|
74
|
+
if num_of_lines > 0 && (num_of_lines < total_lines)
|
|
75
|
+
height -= (total_lines - num_of_lines) * self.font.lineHeight
|
|
76
|
+
elsif (num_of_lines > 0 && (num_of_lines > total_lines))
|
|
77
|
+
height += (num_of_lines - total_lines) * self.font.lineHeight
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
width = text_bounds.size.width.ceil
|
|
81
|
+
height = (attributedText && attributedText.mutableString.blank?) ? 0 : height.ceil
|
|
82
|
+
CGRectMake(text_bounds.origin.x, text_bounds.origin.y, width, height)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# Override UIView methods
|
|
86
|
+
def requiresConstraintBasedLayout
|
|
87
|
+
true
|
|
88
|
+
end
|
|
89
|
+
|
|
31
90
|
def customize(&block)
|
|
32
91
|
@customizing = true
|
|
33
92
|
block.call(self)
|
|
@@ -239,6 +298,7 @@ module EnchantedQuill
|
|
|
239
298
|
text_storage.addLayoutManager(layout_manager)
|
|
240
299
|
layout_manager.addTextContainer(text_container)
|
|
241
300
|
text_container.lineFragmentPadding = 0
|
|
301
|
+
text_container.maximumNumberOfLines = 0
|
|
242
302
|
self.userInteractionEnabled = true
|
|
243
303
|
end
|
|
244
304
|
end
|
|
@@ -266,22 +326,31 @@ module EnchantedQuill
|
|
|
266
326
|
|
|
267
327
|
attributed_text = attributedText
|
|
268
328
|
if attributed_text.nil? || attributed_text.length == 0
|
|
269
|
-
text_storage.setAttributedString(NSAttributedString.alloc.
|
|
329
|
+
text_storage.setAttributedString(NSAttributedString.alloc.initWithString(''))
|
|
270
330
|
return
|
|
271
331
|
end
|
|
272
332
|
|
|
273
333
|
mut_attr_string = add_line_break(attributed_text)
|
|
334
|
+
mut_attr_string = add_default_attributes(mut_attr_string)
|
|
274
335
|
|
|
275
336
|
if parse_text
|
|
276
337
|
@selected_element = nil
|
|
277
|
-
active_elements
|
|
278
|
-
|
|
338
|
+
@active_elements = {}
|
|
339
|
+
|
|
340
|
+
Dispatch::Queue.concurrent.async do
|
|
341
|
+
parse_text_and_extract_active_elements(mut_attr_string)
|
|
342
|
+
active_elements_values = @active_elements.values.flatten.compact
|
|
343
|
+
|
|
344
|
+
if active_elements_values.count > 0
|
|
345
|
+
Dispatch::Queue.main.async do
|
|
346
|
+
add_link_attribute(mut_attr_string)
|
|
347
|
+
text_storage.setAttributedString(mut_attr_string)
|
|
348
|
+
setNeedsDisplay
|
|
349
|
+
end
|
|
350
|
+
end
|
|
279
351
|
end
|
|
280
|
-
|
|
281
|
-
parse_text_and_extract_active_elements(mut_attr_string)
|
|
282
352
|
end
|
|
283
353
|
|
|
284
|
-
add_link_attribute(mut_attr_string)
|
|
285
354
|
text_storage.setAttributedString(mut_attr_string)
|
|
286
355
|
setNeedsDisplay
|
|
287
356
|
end
|
|
@@ -293,8 +362,7 @@ module EnchantedQuill
|
|
|
293
362
|
CGPointMake(rect.origin.x, glyph_origin_y)
|
|
294
363
|
end
|
|
295
364
|
|
|
296
|
-
|
|
297
|
-
def add_link_attribute(mut_attr_string)
|
|
365
|
+
def add_default_attributes(mut_attr_string)
|
|
298
366
|
range_pointer = Pointer.new(NSRange.type)
|
|
299
367
|
attributes = mut_attr_string.attributesAtIndex(0, effectiveRange: range_pointer).dup
|
|
300
368
|
|
|
@@ -302,8 +370,17 @@ module EnchantedQuill
|
|
|
302
370
|
attributes[NSForegroundColorAttributeName] = self.textColor
|
|
303
371
|
|
|
304
372
|
mut_attr_string.addAttributes(attributes, range: range_pointer[0])
|
|
373
|
+
mut_attr_string
|
|
374
|
+
end
|
|
305
375
|
|
|
306
|
-
|
|
376
|
+
# add link attribute
|
|
377
|
+
def add_link_attribute(mut_attr_string)
|
|
378
|
+
range_pointer = Pointer.new(NSRange.type)
|
|
379
|
+
attributes = mut_attr_string.attributesAtIndex(0, effectiveRange: range_pointer).dup
|
|
380
|
+
|
|
381
|
+
attributes[NSFontAttributeName] = self.font
|
|
382
|
+
attributes[NSForegroundColorAttributeName] = self.textColor
|
|
383
|
+
mut_attr_string.addAttributes(attributes, range: range_pointer[0])
|
|
307
384
|
|
|
308
385
|
active_elements.each do |type, elements|
|
|
309
386
|
case type
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: enchanted_quill
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Elom Gomez
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-04-
|
|
11
|
+
date: 2016-04-11 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rake
|