typogrify 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ == 0.0.1 / 2007-08-10
2
+
3
+ * First release
@@ -0,0 +1,7 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ lib/typogrify.rb
6
+ lib/typogrify/typogrify.rb
7
+ lib/typogrify/string.rb
@@ -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.
@@ -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
@@ -0,0 +1,7 @@
1
+ # Load typogrify & string mixin
2
+ path = File.dirname(__FILE__) + "/typogrify/"
3
+ %w(typogrify string).each{|r| require path + r}
4
+
5
+ class Typogrify #:nodoc
6
+ VERSION = "0.0.1"
7
+ end
@@ -0,0 +1,5 @@
1
+ class String
2
+ def typogrify
3
+ Typogrify.convert self
4
+ end
5
+ end
@@ -0,0 +1,36 @@
1
+ %w(rubygems rubypants).each{|r| require r }
2
+ class Typogrify
3
+ attr_accessor :string
4
+
5
+ REPLACEMENTS = [
6
+ {:find => /(&#38;|&amp;)/, :replace => '<span class="amp">&#38;</span>'}, # amp entities
7
+ {:find => '&#8216;', :replace => '<span class="lsquo">&#8216;</span>'}, # single_left_quotes
8
+ {:find => '&#8217;', :replace => '<span class="rsquo">&#8217;</span>'}, # single_right_quotes
9
+ {:find => '&#8220;', :replace => '<span class="laquo">&#8220;</span>'}, # double_left_quotes
10
+ {:find => '&#8221;', :replace => '<span class="raquo">&#8221;</span>'}, # double_right_quotes
11
+ {:find => /(\w+)([^\w]*)$/, :replace => '&nbsp; \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">&#38;</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: