├── .gitmodules
├── node.js
├── lib
├── twitter-text-node.js
└── twitter-text.js
├── LICENSE
├── Rakefile
├── README.textile
└── test
├── test.html.erb
└── test.html
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "test/twitter-text-conformance"]
2 | path = test/twitter-text-conformance
3 | url = http://github.com/mzsanford/twitter-text-conformance.git
4 |
--------------------------------------------------------------------------------
/node.js:
--------------------------------------------------------------------------------
1 | // just to test out the twitter module
2 | sys = require('sys');
3 | twitter = require('./lib/twitter-text-node');
4 |
5 | sys.puts(twitter.auto_link("@hello #there http://google.com"));
--------------------------------------------------------------------------------
/lib/twitter-text-node.js:
--------------------------------------------------------------------------------
1 | var Script = process.binding('evals').Script;
2 | read = require('fs').readFileSync
3 | sys = require('sys')
4 |
5 | Script.runInThisContext(read('lib/twitter-text.js'));
6 |
7 | // exported functions
8 | [
9 | 'auto_link_urls_custom',
10 | 'auto_link',
11 | 'auto_link_usernames_or_lists',
12 | 'auto_link_hashtags',
13 | 'extract_mentioned_screen_names',
14 | 'extract_reply_screen_name',
15 | 'extract_urls',
16 | 'extract_hashtags'
17 | ].forEach(function(method){
18 | exports[method] = TwitterText[method]
19 | })
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright 2010 Twitter, Inc.
2 |
3 | Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 | use this file except in compliance with the License. You may obtain a copy of
5 | the License at
6 |
7 | http://www.apache.org/licenses/LICENSE-2.0
8 |
9 | Unless required by applicable law or agreed to in writing, software
10 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 | License for the specific language governing permissions and limitations under
13 | the License.
14 |
--------------------------------------------------------------------------------
/Rakefile:
--------------------------------------------------------------------------------
1 | require 'rubygems'
2 | require 'rake'
3 | require 'yaml'
4 | require 'erb'
5 | require 'active_support'
6 |
7 | desc "Generate test.html"
8 | task :generate_test do
9 | template = File.read('test/test.html.erb')
10 | autolink = File.read('test/twitter-text-conformance/autolink.yml');
11 | extract = File.read('test/twitter-text-conformance/extract.yml');
12 | hit_highlighting = File.read('test/twitter-text-conformance/hit_highlighting.yml')
13 |
14 | class TestTemplate
15 |
16 | def initialize(autolink_json, extract_json, hit_highlighting_json)
17 | @autolink_json = autolink_json
18 | @extract_json = extract_json
19 | @hit_highlighting_json = hit_highlighting_json
20 | end
21 |
22 | def get_binding
23 | binding
24 | end
25 | end
26 |
27 | template = ERB.new(template)
28 | t = TestTemplate.new(YAML.load(autolink).to_json, YAML.load(extract).to_json, YAML.load(hit_highlighting).to_json)
29 | html = template.result(t.get_binding)
30 | File.open('test/test.html', 'w+') do |file|
31 | file.print(html)
32 | end
33 | end
--------------------------------------------------------------------------------
/README.textile:
--------------------------------------------------------------------------------
1 | h1. Twitter Text in javascript
2 |
3 | An autolinking and extracting library for use in the DOM.
4 |
5 | More info on twitter-text "here":http://engineering.twitter.com/2010/02/introducing-open-source-twitter-text.html
6 |
7 | Based of the "twitter-text-rb library":http://github.com/mzsanford/twitter-text-rb
8 |
9 | Main goal is to achieve 100 percent conformance. More about conformance "here":http://github.com/mzsanford/twitter-text-conformance
10 |
11 | To run the conformance tests just open test/test.html in your browser.
12 |
13 | h2. How To:
14 |
15 | * Download the project from "github":http://github.com/rubymaverick/twitter-text-js.
16 | * Include the lib/twitter-text.js file in your html.
17 |
18 | h2. Testing:
19 |
20 | * First, generate the test.html file by running @rake generate_tests@ in the project root. This uses the test.html.erb file to generate tests, converting the twitter-text-conformance yaml files to json and writing tests against those. Then just open up test.html in your browser to run the tests. If you change the test.html.erb file than you have to run @rake generate_tests@ again.
21 |
22 | h2. Examples:
23 |
24 | @TwitterText.auto_link("This is a #tweet with a @username");@
25 | @// This is a #tweet with a username@
26 |
27 | h2. TODO:
28 |
29 | * Figure out the last couple of url regexp bugs
30 | * Convert to Node.js?
31 |
--------------------------------------------------------------------------------
/test/test.html.erb:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |