fast-aleck 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.
- data/ChangeLog +0 -0
- data/LICENSE +0 -0
- data/NEWS.md +0 -0
- data/README.md +15 -0
- data/fast-aleck.gemspec +23 -0
- data/lib/fast-aleck.rb +54 -0
- data/lib/fast-aleck/nanoc.rb +21 -0
- metadata +59 -0
data/ChangeLog
ADDED
File without changes
|
data/LICENSE
ADDED
File without changes
|
data/NEWS.md
ADDED
File without changes
|
data/README.md
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# Fast Aleck Ruby bindings
|
2
|
+
|
3
|
+
This library contains Ruby bindings (using FFI) for Fast Aleck. Fast Aleck is a tool for making text look smarter by using proper Unicode characters. For example, ... becomes … (`…`) and -- becomes — (`—`). Its goal is to be the fastest text cleaning tool out there.
|
4
|
+
|
5
|
+
The main module is {FastAleck}. The only public function is {FastAleck.process}. The FFI bindings are located in {FastAleck::C}.
|
6
|
+
|
7
|
+
Note: This documentation looks best with Yardoc, not RDoc.
|
8
|
+
|
9
|
+
## Dependencies
|
10
|
+
|
11
|
+
Only FFI. You will obviously also need to have Fast Aleck installed.
|
12
|
+
|
13
|
+
## Contact
|
14
|
+
|
15
|
+
You can reach me at <denis.defreyne@stoneship.org>.
|
data/fast-aleck.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift(File.expand_path('../lib/', __FILE__))
|
4
|
+
require 'fast-aleck'
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = 'fast-aleck'
|
8
|
+
s.version = FastAleck::VERSION
|
9
|
+
s.homepage = 'http://stoneship.org/software/fast-aleck/' # TODO CREATE A WEB SITE YOU SILLY PERSON
|
10
|
+
s.summary = 'a fast typographical improvement library'
|
11
|
+
s.description = 'Fast Aleck lets your text use proper ellipses, smart quotes, proper dashes and more.'
|
12
|
+
|
13
|
+
s.author = 'Denis Defreyne'
|
14
|
+
s.email = 'denis.defreyne@stoneship.org'
|
15
|
+
|
16
|
+
s.files = Dir['[A-Z]*'] +
|
17
|
+
Dir['{lib,test}/**/*'] +
|
18
|
+
[ 'fast-aleck.gemspec' ]
|
19
|
+
s.require_paths = [ 'lib' ]
|
20
|
+
|
21
|
+
s.rdoc_options = [ '--main', 'README.md' ]
|
22
|
+
s.extra_rdoc_files = [ 'ChangeLog', 'LICENSE', 'README.md', 'NEWS.md' ]
|
23
|
+
end
|
data/lib/fast-aleck.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: utf-8
|
3
|
+
|
4
|
+
require 'ffi'
|
5
|
+
|
6
|
+
module FastAleck
|
7
|
+
|
8
|
+
VERSION = '0.1'
|
9
|
+
|
10
|
+
# @api private
|
11
|
+
module C
|
12
|
+
|
13
|
+
extend FFI::Library
|
14
|
+
|
15
|
+
ffi_lib FFI::Library::LIBC
|
16
|
+
ffi_lib 'fast-aleck'
|
17
|
+
|
18
|
+
# @api private
|
19
|
+
class Config < ::FFI::Struct
|
20
|
+
layout :wrap_amps, :char,
|
21
|
+
:wrap_caps, :char,
|
22
|
+
:wrap_quotes, :char,
|
23
|
+
:widont, :char
|
24
|
+
end
|
25
|
+
|
26
|
+
attach_function :fast_aleck, [ Config.by_value, :string, :int, :pointer ], :pointer
|
27
|
+
attach_function :free, [ :pointer ], :void
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
# Processes the given string.
|
32
|
+
#
|
33
|
+
# @option params [Boolean] :wrap_amps (false) true if ampersands should be
|
34
|
+
# wrapped in `<span class="amp">`, false if not
|
35
|
+
#
|
36
|
+
# @option params [Boolean] :wrap_quotes (false) true if single quotes should
|
37
|
+
# be wrapped in `<span class="quo">` and double quotes in
|
38
|
+
# `<span class="dquo">`, false if not
|
39
|
+
#
|
40
|
+
# @return [String] The processed string
|
41
|
+
def self.process(s, params={})
|
42
|
+
config = ::FastAleck::C::Config.new
|
43
|
+
config[:wrap_amps] = params[:wrap_amps] ? 1 : 0
|
44
|
+
config[:wrap_caps] = params[:wrap_caps] ? 1 : 0
|
45
|
+
config[:wrap_quotes] = params[:wrap_quotes] ? 1 : 0
|
46
|
+
config[:widont] = params[:widont] ? 1 : 0
|
47
|
+
|
48
|
+
ptr = ::FastAleck::C.fast_aleck(config, s, s.size, FFI::Pointer::NULL)
|
49
|
+
str = ptr.read_string_to_null
|
50
|
+
::FastAleck::C.free(ptr)
|
51
|
+
str
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'fast-aleck'
|
4
|
+
require 'nanoc'
|
5
|
+
|
6
|
+
module FastAleck
|
7
|
+
|
8
|
+
# A Fast Aleck filter for [nanoc](http://nanoc.stoneship.org/).
|
9
|
+
class NanocFilter < ::Nanoc::Filter
|
10
|
+
|
11
|
+
identifier :fast_aleck
|
12
|
+
|
13
|
+
def run(content, params={})
|
14
|
+
res = FastAleck.process(content, params)
|
15
|
+
res.force_encoding('utf-8')
|
16
|
+
res
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fast-aleck
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Denis Defreyne
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-05-12 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Fast Aleck lets your text use proper ellipses, smart quotes, proper dashes
|
15
|
+
and more.
|
16
|
+
email: denis.defreyne@stoneship.org
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files:
|
20
|
+
- ChangeLog
|
21
|
+
- LICENSE
|
22
|
+
- README.md
|
23
|
+
- NEWS.md
|
24
|
+
files:
|
25
|
+
- ChangeLog
|
26
|
+
- LICENSE
|
27
|
+
- NEWS.md
|
28
|
+
- README.md
|
29
|
+
- lib/fast-aleck/nanoc.rb
|
30
|
+
- lib/fast-aleck.rb
|
31
|
+
- fast-aleck.gemspec
|
32
|
+
homepage: http://stoneship.org/software/fast-aleck/
|
33
|
+
licenses: []
|
34
|
+
post_install_message:
|
35
|
+
rdoc_options:
|
36
|
+
- --main
|
37
|
+
- README.md
|
38
|
+
require_paths:
|
39
|
+
- lib
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
|
+
none: false
|
48
|
+
requirements:
|
49
|
+
- - ! '>='
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
requirements: []
|
53
|
+
rubyforge_project:
|
54
|
+
rubygems_version: 1.8.24
|
55
|
+
signing_key:
|
56
|
+
specification_version: 3
|
57
|
+
summary: a fast typographical improvement library
|
58
|
+
test_files: []
|
59
|
+
has_rdoc:
|