typogrify 0.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/History.txt +3 -0
- data/Manifest.txt +7 -0
- data/README.txt +58 -0
- data/Rakefile +19 -0
- data/lib/typogrify.rb +7 -0
- data/lib/typogrify/string.rb +5 -0
- data/lib/typogrify/typogrify.rb +36 -0
- metadata +72 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
Typogrify
|
2
|
+
by Ben Schwarz
|
3
|
+
http://germanforblack.com/
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
A direct copy of Typogrify for Django with minor opinionated changes (class names and elements being wrapped)
|
8
|
+
|
9
|
+
Thanks to Pat Allan & his regex-fu, Anthony Kolber (http://aestheticallyloyal.com/) for showing me Typogrify.
|
10
|
+
|
11
|
+
Square Circle Triangle (http://sct.com.au/) because I mashed it together on a Friday afternoon at work :)
|
12
|
+
|
13
|
+
== FEATURES/PROBLEMS:
|
14
|
+
|
15
|
+
* Multiple adjacent caps are wrapped in <span class="caps"> (Gives you a handle on small caps)
|
16
|
+
* Single and double quotes are wrapped in a class name matching their entity name in HTML
|
17
|
+
* Ampersands wrapped in <span class="amp">
|
18
|
+
* Runs smarty pants (Which writes HTML entities so that you don't have to)
|
19
|
+
* No more widows in your headlines
|
20
|
+
* Extends the string class
|
21
|
+
|
22
|
+
== USAGE:
|
23
|
+
|
24
|
+
%w(rubygems typogrify).each{|r| require r}
|
25
|
+
'"Jayhawks" & KU fans act extremely obnoxiously'.typogrify
|
26
|
+
|
27
|
+
== REQUIREMENTS:
|
28
|
+
|
29
|
+
* Rubypants
|
30
|
+
|
31
|
+
== INSTALL:
|
32
|
+
|
33
|
+
* sudo gem install typogrify --include-dependencies
|
34
|
+
|
35
|
+
== LICENSE:
|
36
|
+
|
37
|
+
(The MIT License)
|
38
|
+
|
39
|
+
Copyright (c) 2007 Ben Schwarz
|
40
|
+
|
41
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
42
|
+
a copy of this software and associated documentation files (the
|
43
|
+
'Software'), to deal in the Software without restriction, including
|
44
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
45
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
46
|
+
permit persons to whom the Software is furnished to do so, subject to
|
47
|
+
the following conditions:
|
48
|
+
|
49
|
+
The above copyright notice and this permission notice shall be
|
50
|
+
included in all copies or substantial portions of the Software.
|
51
|
+
|
52
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
53
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
54
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
55
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
56
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
57
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
58
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'hoe'
|
5
|
+
require './lib/typogrify.rb'
|
6
|
+
|
7
|
+
Hoe.new('typogrify', Typogrify::VERSION) do |p|
|
8
|
+
p.rubyforge_name = 'typogrify'
|
9
|
+
p.author = 'Ben Schwarz'
|
10
|
+
p.email = 'ben.schwarz@gmail.com'
|
11
|
+
p.summary = 'Tidy your plain text to create beautiful HTML headlines'
|
12
|
+
p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
|
13
|
+
p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1]
|
14
|
+
p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
|
15
|
+
p.extra_deps = ['rubypants', '0.2']
|
16
|
+
p.remote_rdoc_dir = ''
|
17
|
+
end
|
18
|
+
|
19
|
+
# vim: syntax=Ruby
|
data/lib/typogrify.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
%w(rubygems rubypants).each{|r| require r }
|
2
|
+
class Typogrify
|
3
|
+
attr_accessor :string
|
4
|
+
|
5
|
+
REPLACEMENTS = [
|
6
|
+
{:find => /(&|&)/, :replace => '<span class="amp">&</span>'}, # amp entities
|
7
|
+
{:find => '‘', :replace => '<span class="lsquo">‘</span>'}, # single_left_quotes
|
8
|
+
{:find => '’', :replace => '<span class="rsquo">’</span>'}, # single_right_quotes
|
9
|
+
{:find => '“', :replace => '<span class="laquo">“</span>'}, # double_left_quotes
|
10
|
+
{:find => '”', :replace => '<span class="raquo">”</span>'}, # double_right_quotes
|
11
|
+
{:find => /(\w+)([^\w]*)$/, :replace => ' \1\2'}, # widows
|
12
|
+
{:find => /([^\w]*)([A-Z]{2,})([^\w]*)/, :replace => '\1<span class="caps">\2</span>\3'}, # small_caps
|
13
|
+
{:find => ' & ', :replace => ' <span class="amp">&</span> '} # amps with spaces surrounding them
|
14
|
+
]
|
15
|
+
|
16
|
+
def self.convert(string)
|
17
|
+
converter = Typogrify.new(string)
|
18
|
+
converter.entities
|
19
|
+
converter.replace_text
|
20
|
+
converter.string
|
21
|
+
end
|
22
|
+
|
23
|
+
def initialize(string)
|
24
|
+
@string = string
|
25
|
+
end
|
26
|
+
|
27
|
+
def replace_text
|
28
|
+
REPLACEMENTS.each do |replacement|
|
29
|
+
@string.gsub!(replacement[:find], replacement[:replace])
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def entities
|
34
|
+
@string = RubyPants.new(@string).to_html
|
35
|
+
end
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.3
|
3
|
+
specification_version: 1
|
4
|
+
name: typogrify
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.0.1
|
7
|
+
date: 2007-08-12 00:00:00 +10:00
|
8
|
+
summary: Tidy your plain text to create beautiful HTML headlines
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: ben.schwarz@gmail.com
|
12
|
+
homepage: " by Ben Schwarz"
|
13
|
+
rubyforge_project: typogrify
|
14
|
+
description: "Thanks to Pat Allan & his regex-fu, Anthony Kolber (http://aestheticallyloyal.com/) for showing me Typogrify. Square Circle Triangle (http://sct.com.au/) because I mashed it together on a Friday afternoon at work :) == FEATURES/PROBLEMS: * Multiple adjacent caps are wrapped in <span class=\"caps\"> (Gives you a handle on small caps) * Single and double quotes are wrapped in a class name matching their entity name in HTML * Ampersands wrapped in <span class=\"amp\"> * Runs smarty pants (Which writes HTML entities so that you don't have to) * No more widows in your headlines * Extends the string class == USAGE:"
|
15
|
+
autorequire:
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
30
|
+
- Ben Schwarz
|
31
|
+
files:
|
32
|
+
- History.txt
|
33
|
+
- Manifest.txt
|
34
|
+
- README.txt
|
35
|
+
- Rakefile
|
36
|
+
- lib/typogrify.rb
|
37
|
+
- lib/typogrify/typogrify.rb
|
38
|
+
- lib/typogrify/string.rb
|
39
|
+
test_files: []
|
40
|
+
|
41
|
+
rdoc_options:
|
42
|
+
- --main
|
43
|
+
- README.txt
|
44
|
+
extra_rdoc_files:
|
45
|
+
- History.txt
|
46
|
+
- Manifest.txt
|
47
|
+
- README.txt
|
48
|
+
executables: []
|
49
|
+
|
50
|
+
extensions: []
|
51
|
+
|
52
|
+
requirements: []
|
53
|
+
|
54
|
+
dependencies:
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubypants
|
57
|
+
version_requirement:
|
58
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: "0.2"
|
63
|
+
version:
|
64
|
+
- !ruby/object:Gem::Dependency
|
65
|
+
name: hoe
|
66
|
+
version_requirement:
|
67
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: 1.2.2
|
72
|
+
version:
|