typographer-addons 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +15 -0
- data/Gemfile +7 -0
- data/README +0 -0
- data/Rakefile +2 -0
- data/autotest/discover.rb +1 -0
- data/lib/typographer-addons.rb +5 -0
- data/lib/typographer-addons/add_class_to_first_paragraph.rb +19 -0
- data/lib/typographer-addons/add_to_last_paragraph.rb +23 -0
- data/lib/typographer-addons/version.rb +5 -0
- data/lib/typographer-addons/wrap_first_letter.rb +26 -0
- data/spec/add_class_to_first_paragraph_spec.rb +17 -0
- data/spec/add_to_last_paragraph_spec.rb +9 -0
- data/spec/spec_helper.rb +8 -0
- data/spec/wrap_first_letter_spec.rb +20 -0
- data/typographer-addons.gemspec +26 -0
- metadata +108 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README
ADDED
File without changes
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Autotest.add_discovery { "rspec2" }
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module TypographerHelper
|
3
|
+
module Parsers
|
4
|
+
class AddClassToFirstParagraph
|
5
|
+
def initialize(options = {})
|
6
|
+
@options = options
|
7
|
+
@options[:class] ||= 'first_paragraph'
|
8
|
+
@options[:matcher] ||= 'p'
|
9
|
+
end
|
10
|
+
|
11
|
+
def parse(string)
|
12
|
+
doc = Nokogiri.HTML string
|
13
|
+
target = doc.css(@options[:matcher]).first
|
14
|
+
target['class'] = target['class'].blank? ? @options[:class] : target['class'] + ' ' + @options[:class]
|
15
|
+
doc.search('body').children.to_xhtml
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module TypographerHelper
|
3
|
+
module Parsers
|
4
|
+
class AddToLastParagraph
|
5
|
+
def initialize(options = {})
|
6
|
+
@options = options
|
7
|
+
@options[:text] ||= ''
|
8
|
+
@options[:matcher] ||= 'p:last-of-type'
|
9
|
+
end
|
10
|
+
|
11
|
+
def parse(string)
|
12
|
+
#TODO: swap code after resolving issue https://github.com/tenderlove/nokogiri/issues/454
|
13
|
+
#doc = Nokogiri::HTML.fragment(string)
|
14
|
+
#doc.css(@options[:matcher]).first.add_child(@options[:text])
|
15
|
+
#doc.to_s
|
16
|
+
|
17
|
+
doc = Nokogiri.HTML string
|
18
|
+
doc.css(@options[:matcher]).first.add_child(@options[:text])
|
19
|
+
doc.search('body').children.to_xhtml
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module TypographerHelper
|
3
|
+
module Parsers
|
4
|
+
class WrapFirstLetter
|
5
|
+
def initialize(options = {})
|
6
|
+
@options = options
|
7
|
+
@options[:text] ||= Proc.new { |letter| '<span class="first_letter">'+letter+'</span>'}
|
8
|
+
@options[:matcher] ||= 'p:first'
|
9
|
+
end
|
10
|
+
|
11
|
+
def parse(string)
|
12
|
+
doc = Nokogiri.HTML string
|
13
|
+
target = doc.css(@options[:matcher]).first
|
14
|
+
text = target.inner_html
|
15
|
+
|
16
|
+
unless text.blank?
|
17
|
+
match = /(<([^>]+)>|\s)*(.)/.match text
|
18
|
+
new_text_part = @options[:text].call(match[3])
|
19
|
+
target.inner_html = text[0...match.offset(3)[0]] + new_text_part + text[match.offset(3)[1]...text.length]
|
20
|
+
end
|
21
|
+
|
22
|
+
doc.search('body').children.to_xhtml
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe TypographerHelper::Parsers::AddClassToFirstParagraph, ' last paragraph parser' do |target|
|
5
|
+
before :all do |spec|
|
6
|
+
TypographerHelper.register :default, [spec.described_class.new]
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should add class to first <p>" do
|
10
|
+
ty('<div>Not paragraph</div><p>Lorem ipsum</p><p>Second paragraph</p>').should == '<div>Not paragraph</div><p class="first_paragraph">Lorem ipsum</p><p>Second paragraph</p>'
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should add class to first <p> already with class" do
|
14
|
+
ty('<div>Not paragraph</div><p class="old_class">Lorem ipsum</p><p>Second paragraph</p>').should == '<div>Not paragraph</div><p class="old_class first_paragraph">Lorem ipsum</p><p>Second paragraph</p>'
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe TypographerHelper::Parsers::AddToLastParagraph, ' last paragraph parser' do
|
5
|
+
it "should add to last paragraph" do |spec|
|
6
|
+
TypographerHelper.register :default, [spec.described_class.new(:text => 'ADDED')]
|
7
|
+
ty('<p>Lorem ipsum</p><p>Second paragraph</p><div>Not paragraph</div>').should == '<p>Lorem ipsum</p><p>Second paragraphADDED</p><div>Not paragraph</div>'
|
8
|
+
end
|
9
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe TypographerHelper::Parsers::WrapFirstLetter, ' last paragraph parser' do |target|
|
5
|
+
before :all do |spec|
|
6
|
+
TypographerHelper.register :default, [spec.described_class.new]
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should wrap first letter in first <p>" do
|
10
|
+
ty('<div>Not paragraph</div><p>Lorem ipsum</p><p>Second paragraph</p>').should == '<div>Not paragraph</div><p><span class="first_letter">L</span>orem ipsum</p><p>Second paragraph</p>'
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should wrap first letter in first <p>, starting with tag" do
|
14
|
+
ty('<div>Not paragraph</div><p><span></span>Lorem ipsum</p><p>Second paragraph</p>').should == '<div>Not paragraph</div><p><span></span><span class="first_letter">L</span>orem ipsum</p><p>Second paragraph</p>'
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should wrap first letter in first <p>, starting with space" do
|
18
|
+
ty('<div>Not paragraph</div><p> Lorem ipsum</p><p>Second paragraph</p>').should == '<div>Not paragraph</div><p> <span class="first_letter">L</span>orem ipsum</p><p>Second paragraph</p>'
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "typographer-addons/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = TypographerAddons::GEM_NAME
|
7
|
+
s.version = TypographerAddons::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Alexander Rozumiy", 'Andrey Savchenko', 'Anton Versal']
|
10
|
+
s.email = ["brain-geek@yandex.ua"]
|
11
|
+
s.homepage = "https://github.com/Slotos/typographer-addons"
|
12
|
+
s.summary = "#{TypographerAddons::GEM_NAME}-#{TypographerAddons::VERSION}"
|
13
|
+
s.description = %q{Additional plugins for typographer gem}
|
14
|
+
|
15
|
+
s.rubyforge_project = "typographer-addons"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_dependency "typographer"
|
23
|
+
s.add_dependency "nokogiri"
|
24
|
+
s.add_development_dependency "rspec", ">= 2.0.0"
|
25
|
+
s.add_development_dependency "autotest"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: typographer-addons
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Alexander Rozumiy
|
9
|
+
- Andrey Savchenko
|
10
|
+
- Anton Versal
|
11
|
+
autorequire:
|
12
|
+
bindir: bin
|
13
|
+
cert_chain: []
|
14
|
+
date: 2011-07-18 00:00:00.000000000 +03:00
|
15
|
+
default_executable:
|
16
|
+
dependencies:
|
17
|
+
- !ruby/object:Gem::Dependency
|
18
|
+
name: typographer
|
19
|
+
requirement: &70812250 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ! '>='
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: '0'
|
25
|
+
type: :runtime
|
26
|
+
prerelease: false
|
27
|
+
version_requirements: *70812250
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: nokogiri
|
30
|
+
requirement: &70812030 !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ! '>='
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
type: :runtime
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: *70812030
|
39
|
+
- !ruby/object:Gem::Dependency
|
40
|
+
name: rspec
|
41
|
+
requirement: &70811780 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 2.0.0
|
47
|
+
type: :development
|
48
|
+
prerelease: false
|
49
|
+
version_requirements: *70811780
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: autotest
|
52
|
+
requirement: &70811570 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ! '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
type: :development
|
59
|
+
prerelease: false
|
60
|
+
version_requirements: *70811570
|
61
|
+
description: Additional plugins for typographer gem
|
62
|
+
email:
|
63
|
+
- brain-geek@yandex.ua
|
64
|
+
executables: []
|
65
|
+
extensions: []
|
66
|
+
extra_rdoc_files: []
|
67
|
+
files:
|
68
|
+
- .gitignore
|
69
|
+
- Gemfile
|
70
|
+
- README
|
71
|
+
- Rakefile
|
72
|
+
- autotest/discover.rb
|
73
|
+
- lib/typographer-addons.rb
|
74
|
+
- lib/typographer-addons/add_class_to_first_paragraph.rb
|
75
|
+
- lib/typographer-addons/add_to_last_paragraph.rb
|
76
|
+
- lib/typographer-addons/version.rb
|
77
|
+
- lib/typographer-addons/wrap_first_letter.rb
|
78
|
+
- spec/add_class_to_first_paragraph_spec.rb
|
79
|
+
- spec/add_to_last_paragraph_spec.rb
|
80
|
+
- spec/spec_helper.rb
|
81
|
+
- spec/wrap_first_letter_spec.rb
|
82
|
+
- typographer-addons.gemspec
|
83
|
+
has_rdoc: true
|
84
|
+
homepage: https://github.com/Slotos/typographer-addons
|
85
|
+
licenses: []
|
86
|
+
post_install_message:
|
87
|
+
rdoc_options: []
|
88
|
+
require_paths:
|
89
|
+
- lib
|
90
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
91
|
+
none: false
|
92
|
+
requirements:
|
93
|
+
- - ! '>='
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
requirements: []
|
103
|
+
rubyforge_project: typographer-addons
|
104
|
+
rubygems_version: 1.6.2
|
105
|
+
signing_key:
|
106
|
+
specification_version: 3
|
107
|
+
summary: typographer-addons-0.1.0
|
108
|
+
test_files: []
|