anchors 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 163b1b68541c2d11b9189be4a3acf89bc60529d1
4
+ data.tar.gz: ccf418e7425255accf64119986a923b670236bbd
5
+ SHA512:
6
+ metadata.gz: 55a35235e831d45f673385e2b880caccd648029e953e0aba1e4e2e07a9f338e69f3edc431f57a1d3144cba48e3e2c25ef3370893db25429b50035315fa88e88e
7
+ data.tar.gz: 1e83423313f7de591ae85086bffc583233a808c3ecc17119d78c8e7a93488a420ec7a65e32c3341f0df49ea8dbbfd2811379d4c52475e3dd602f962d825917be
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in anchors.gemspec
4
+ gemspec
@@ -0,0 +1,51 @@
1
+ # ⚓ Anchors ⚓
2
+
3
+ This gem will add anchors to all of your websites h1-h6 headers. Its useful for static website generators, like Middleman.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'anchors'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install anchors
20
+
21
+ ## Usage
22
+
23
+ Just use the middleware from your rack config.ru file or Middleman config.rb file as follows:
24
+
25
+ ```ruby
26
+ require "anchors"
27
+ use Anchors::Middleware
28
+ ```
29
+
30
+ and the `body` will automatically have anchors applied to all of the h1-h6 tags.
31
+
32
+ If you don't want to apply anchors to all of your requests, just pass a CSS selector into the middleware:
33
+
34
+ ```ruby
35
+ require "anchors"
36
+ use Anchors::Middleware,
37
+ css: "section.anchorize", # CSS headers are applied to. Defaults to 'body'
38
+ seperator: "-", # Change the seperator in the header. Defaults to _
39
+ link: false # Don't convert the headers into links to their own anchors. Defaults to true.
40
+ ```
41
+
42
+ ## Development
43
+
44
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
45
+
46
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
47
+
48
+ ## Contributing
49
+
50
+ Bug reports and pull requests are welcome on GitHub at https://github.com/bradgessler/anchors.
51
+
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'anchors/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "anchors"
8
+ spec.version = Anchors::VERSION
9
+ spec.authors = ["Brad Gessler"]
10
+ spec.email = ["bradgessler@gmail.com"]
11
+
12
+ spec.summary = %q{Add anchors to your h1-h6 tags in Middleman or Rack}
13
+ spec.homepage = "https://github.com/bradgessler/anchors"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.bindir = "exe"
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.11"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_development_dependency "rspec", "~> 3.0"
23
+ spec.add_development_dependency "rack"
24
+ spec.add_development_dependency "rack-test"
25
+
26
+ spec.add_dependency "rack-plastic", "~> 0.1.0"
27
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "anchors"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,46 @@
1
+ require "anchors/version"
2
+ require "rack-plastic"
3
+
4
+ module Anchors
5
+ class Middleware < Rack::Plastic
6
+ CSS_SELECTOR = "body"
7
+ SEPERATOR = "_"
8
+ LINK = true
9
+
10
+ def change_nokogiri_doc(doc)
11
+ # Throw this CSS class into the HTML page where you
12
+ # want to have linkable anchor headers.
13
+ doc.css(css).each do |node|
14
+ node.css("h1,h2,h3,h4,h5,h6").each do |h|
15
+ id = dom_id(h)
16
+ h["id"] = id
17
+ if link?
18
+ a = Nokogiri::XML::Node.new "a", doc
19
+ a["href"] = "##{h["id"]}"
20
+ a.add_child h.clone
21
+ h.swap a
22
+ end
23
+ end
24
+ end
25
+ doc
26
+ end
27
+
28
+ private
29
+ # Super lame, but awesome way to get CSS options CSS selector.
30
+ def css
31
+ options[:css] || CSS_SELECTOR
32
+ end
33
+
34
+ def seperator
35
+ options[:seperator] || SEPERATOR
36
+ end
37
+
38
+ def link?
39
+ options[:link] || LINK
40
+ end
41
+
42
+ def dom_id(el)
43
+ el.content.downcase.gsub(/[^\d\w\s_]/, '').gsub(' ', '_')
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,3 @@
1
+ module Anchors
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: anchors
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Brad Gessler
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-02-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rack
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rack-test
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rack-plastic
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.1.0
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.1.0
97
+ description:
98
+ email:
99
+ - bradgessler@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - Gemfile
108
+ - README.md
109
+ - Rakefile
110
+ - anchors.gemspec
111
+ - bin/console
112
+ - bin/setup
113
+ - lib/anchors.rb
114
+ - lib/anchors/version.rb
115
+ homepage: https://github.com/bradgessler/anchors
116
+ licenses: []
117
+ metadata: {}
118
+ post_install_message:
119
+ rdoc_options: []
120
+ require_paths:
121
+ - lib
122
+ required_ruby_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ required_rubygems_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ requirements: []
133
+ rubyforge_project:
134
+ rubygems_version: 2.5.1
135
+ signing_key:
136
+ specification_version: 4
137
+ summary: Add anchors to your h1-h6 tags in Middleman or Rack
138
+ test_files: []