twitter-text 2.0.0 → 2.0.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 92e1f709304c7902186bbe50ff5f7d215059d292a4e8730b9cdff12210dff1aa
4
- data.tar.gz: fd50deede86bb5ba1a47ff214350f86a928ed59926438d3361475f3640ff8531
3
+ metadata.gz: 51743434be1b2fd825f0a9ae3dbcc97c0c5fab245dad7f012a9c92e3cc7d1e00
4
+ data.tar.gz: 1571db93e87a73048c4bd7e9940d7c7158f5a02d044fc9a759593e3617a248ec
5
5
  SHA512:
6
- metadata.gz: 85f39c5bd4d9c58b863d5e9490618ee941a528ab8fd23a463857a206d53ba50a4235cb7e287245a0e3bb66bb78955b98cf6973f1ed5e2ec5741090ef34a77c52
7
- data.tar.gz: 6a0133f3acd0a34742435777f4fc276df4639066adc80b39d3a4b84f77ec73eb0772fae0ff52f20e3af752b089ca976de3b215d83241944c2fd0ef8f9823ba85
6
+ metadata.gz: d4189f84389d8ad9c51752a111adc1616d4d1a4063dfa265a492a1d0f0196af785e41e1bce8ea3b6c42aee856b9ccd19f714a9947ae4fce0be7b5d3ed4cd1048
7
+ data.tar.gz: 2026f92f4249c6c0a4cbaa92cac145356edb0adf617e0fc5f3e8fb66ca3eb5a22e9372387997adf4220799270854dc062e444f0858ab7abb802b6b3f7d8f16da
data/Rakefile CHANGED
@@ -2,9 +2,18 @@ require 'bundler'
2
2
  include Rake::DSL
3
3
  Bundler::GemHelper.install_tasks
4
4
 
5
- task :default => ['spec', 'test:conformance']
5
+ task :build => ['prebuild']
6
+ task :spec => ['prebuild']
7
+ task :default => ['prebuild', 'spec', 'test:conformance']
6
8
  task :test => :spec
7
9
 
10
+ directory "config"
11
+
12
+ desc "Prebuild task setup"
13
+ task :prebuild => ["config"] do
14
+ FileUtils.cp_r '../config/.', 'config', :verbose => true
15
+ end
16
+
8
17
  require 'rubygems'
9
18
  require 'rspec/core/rake_task'
10
19
  RSpec::Core::RakeTask.new(:spec)
@@ -12,7 +21,7 @@ RSpec::Core::RakeTask.new(:spec)
12
21
  namespace :test do
13
22
  namespace :conformance do
14
23
  desc "Run conformance test suite"
15
- task :run do
24
+ task :run => ['prebuild'] do
16
25
  ruby '-rubygems', "test/conformance_test.rb"
17
26
  end
18
27
  end
@@ -34,3 +43,8 @@ end
34
43
  desc "Run cruise control build"
35
44
  task :cruise => [:spec, 'test:conformance'] do
36
45
  end
46
+
47
+ desc "Clean build"
48
+ task :clean do
49
+ rm_rf ["config", "pkg", "Gemfile.lock"]
50
+ end
@@ -0,0 +1,134 @@
1
+ # twitter-text Configuration
2
+
3
+ twitter-text 2.0 introduces a new configuration format as well as APIs
4
+ for interpreting this configuration. The configuration is a JSON
5
+ string (or file) and the parsing APIs have been provided in each of
6
+ twitter-text’s four reference languages.
7
+
8
+ ## Format
9
+
10
+ The configuration format is a JSON string. The JSON can have the following properties:
11
+
12
+ * `version` (required, integer, min value 0)
13
+ * `maxWeightedTweetLength` (required, integer, min value 0)
14
+ * `scale` (required, integer, min value 1)
15
+ * `defaultWeight` (required, integer, min value 0)
16
+ * `transformedURLLength` (integer, min value 0)
17
+ * `ranges` (array of range items)
18
+
19
+ A `range item` has the following properties:
20
+
21
+ * `start` (required, integer, min value 0)
22
+ * `end` (required, integer, min value 0)
23
+ * `weight` (required, integer, min value 0)
24
+
25
+ ## Parameters
26
+
27
+ ### version
28
+
29
+ The version for the configuration string. This is an integer that will
30
+ monotonically increase in future releases. The legacy version of the
31
+ string is version 1; weighted code point ranges and 280-character
32
+ “long” tweets are supported in version 2.
33
+
34
+ ### maxWeightedTweetLength
35
+
36
+ The maximum length of the tweet, weighted. Legacy v1 tweets had a
37
+ maximum weighted length of 140 and all characters were weighted the
38
+ same. In the new configuration format, this is represented as a
39
+ maxWeightedTweetLength of 140 and a defaultWeight of 1 for all code
40
+ points.
41
+
42
+ ### scale
43
+
44
+ The Tweet length is the (`weighted length` / `scale`).
45
+
46
+ ### defaultWeight
47
+
48
+ The default weight applied to all code points. This is overridden in
49
+ one or more range items.
50
+
51
+ ### transformedURLLength
52
+
53
+ The length counted for URLs against the total weight of the Tweet. In
54
+ previous versions of twitter-text, which was the “shortened URL
55
+ length.” Differentiating between the http and https shortened length
56
+ for URLs has been deprecated (https is used for all t.co URLs). The
57
+ default value is 23.
58
+
59
+ ### ranges
60
+
61
+ An array of range items that describe ranges of Unicode code points
62
+ and the weight to apply to each code point. Each range is defined by
63
+ its start, end, and weight. Surrogate pairs have a length that is
64
+ equivalent to the length of the first code unit in the surrogate
65
+ pair. Note that certain graphemes are the result of joining code
66
+ points together, such as by a zero-width joiner; unlike a surrogate
67
+ pair, the length of such a grapheme will be the sum of the weighted
68
+ length of all included code points.
69
+
70
+ ## API
71
+
72
+ Each of the four reference language implementations provides a way to
73
+ read the JSON configuration.
74
+
75
+ ## Java
76
+
77
+ ```java
78
+ public static TwitterTextConfiguration configurationFromJson(@Nonnull String json, boolean isResource)
79
+ ```
80
+
81
+ `json`: the configuration string or file name in the config directory (see `isResource`)
82
+ `isResource`: if true, json refers to a file name for the configuration.
83
+
84
+ ## JavaScript
85
+
86
+ Configurations are accessed via `twttr.text.configs` (example:
87
+ `twttr.text.configs.version2`). This config is passed as an argument
88
+ to `parseTweet:`
89
+
90
+ ```js
91
+ twttr.txt.parseTweet(inputText, configVersion2)
92
+ ```
93
+
94
+ ## Objective-C
95
+
96
+ The Objective-C implementation provides two methods for reading the
97
+ input, either from a string or a file resource.
98
+
99
+ ```objective-c
100
+ + (instancetype)configurationFromJSONResource:(NSString *)jsonResource;
101
+ + (instancetype)configurationFromJSONString:(NSString *)jsonString;
102
+ ```
103
+
104
+ The default configuration can also be set:
105
+
106
+ ```objective-c
107
+ + (void)setDefaultParserConfiguration:(TwitterTextConfiguration *)configuration
108
+ ```
109
+
110
+ The resource string refers to the two included configuration files
111
+ (which are referenced in the Xcode project).
112
+
113
+ ## Ruby
114
+
115
+ Ruby provides the `Twitter::Configuration` class and means to read
116
+ from a file or string.
117
+
118
+ ```ruby
119
+ def self.parse_string(string, options = {})
120
+ def self.parse_file(filename)
121
+ ```
122
+
123
+ You can use `configuration_from_file()` or initialize a configuration
124
+ using `Twitter::Configuration.new(config)`, where `config` is the
125
+ output of one of the two above methods.
126
+
127
+
128
+
129
+
130
+
131
+
132
+
133
+
134
+
@@ -0,0 +1,8 @@
1
+ {
2
+ "version": 1,
3
+ "maxWeightedTweetLength": 140,
4
+ "scale": 1,
5
+ "defaultWeight": 1,
6
+ "transformedURLLength": 23,
7
+ "ranges": []
8
+ }
@@ -0,0 +1,29 @@
1
+ {
2
+ "version": 2,
3
+ "maxWeightedTweetLength": 280,
4
+ "scale": 100,
5
+ "defaultWeight": 200,
6
+ "transformedURLLength": 23,
7
+ "ranges": [
8
+ {
9
+ "start": 0,
10
+ "end": 4351,
11
+ "weight": 100
12
+ },
13
+ {
14
+ "start": 8192,
15
+ "end": 8205,
16
+ "weight": 100
17
+ },
18
+ {
19
+ "start": 8208,
20
+ "end": 8223,
21
+ "weight": 100
22
+ },
23
+ {
24
+ "start": 8242,
25
+ "end": 8247,
26
+ "weight": 100
27
+ }
28
+ ]
29
+ }
@@ -15,12 +15,12 @@ module Twitter
15
15
  attr_reader :default_weight, :transformed_url_length, :ranges
16
16
 
17
17
  CONFIG_V1 = File.join(
18
- File.expand_path('../../../../config', __FILE__), # project root
18
+ File.expand_path('../../../config', __FILE__), # project root
19
19
  "#{PARSER_VERSION_CLASSIC}.json"
20
20
  )
21
21
 
22
22
  CONFIG_V2 = File.join(
23
- File.expand_path('../../../../config', __FILE__), # project root
23
+ File.expand_path('../../../config', __FILE__), # project root
24
24
  "#{PARSER_VERSION_DEFAULT}.json"
25
25
  )
26
26
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "twitter-text"
5
- s.version = "2.0.0"
5
+ s.version = "2.0.1"
6
6
  s.authors = ["David LaMacchia", "Sudheer Guntupalli", "Kaushik Lakshmikanth", "Jose Antonio Marquez Russo", "Lee Adams",
7
7
  "Yoshimasa Niwa"]
8
8
  s.email = ["opensource@twitter.com"]
@@ -26,7 +26,7 @@ Gem::Specification.new do |s|
26
26
  # Use of idn-ruby requires libidn to be installed separately
27
27
  s.add_runtime_dependency "idn-ruby"
28
28
 
29
- s.files = `git ls-files`.split("\n") + ['lib/assets/tld_lib.yml']
29
+ s.files = `git ls-files`.split("\n") + ['lib/assets/tld_lib.yml'] + Dir['config/*']
30
30
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
31
31
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
32
32
  s.require_paths = ["lib"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twitter-text
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - David LaMacchia
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2017-12-15 00:00:00.000000000 Z
16
+ date: 2017-12-18 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: pry
@@ -170,6 +170,9 @@ files:
170
170
  - LICENSE
171
171
  - README.md
172
172
  - Rakefile
173
+ - config/README.md
174
+ - config/v1.json
175
+ - config/v2.json
173
176
  - lib/assets/tld_lib.yml
174
177
  - lib/twitter-text.rb
175
178
  - lib/twitter-text/autolink.rb