simple_toc 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: dc635e459d66becbcdffa4e1818101ea6c8fd853
4
+ data.tar.gz: 03ae80d42122e13a51059002df1ff4632e69db74
5
+ SHA512:
6
+ metadata.gz: 619966c04d8b9294ef9e25324c57c57edf89b5c30978850c2482c5e4c5f7a3900bb057bc7f1aebdc4144d908481ee837e7ede89bff690d23a4dc9392b2ca878c
7
+ data.tar.gz: eb5bbfc22491f18deefc9ead783cbecaed9f21f7021e0c6cdfc005721dfc3782a307fe16856b7f4267bda494a3d501603e1733d68a6f8583a7dc53a0baaa11ab
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp
10
+ /vendor/bundle
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in simple_toc.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 miraoto
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,52 @@
1
+ # SimpleToc
2
+
3
+ 'simple-toc' makes a simple table of contents from DOM structure.
4
+
5
+ ## Installation
6
+
7
+ ```ruby
8
+ gem 'simple_toc'
9
+ ```
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install simple_toc
18
+
19
+ ## Usage
20
+
21
+ To require this plguin, add the following to your application.js:
22
+
23
+ ``` javascript
24
+
25
+ //= require simpleToc
26
+
27
+ ```
28
+
29
+ This plugin require jQuery.
30
+
31
+ ``` javascript
32
+ $(function() {
33
+ # simple case
34
+ $('.toc').simpleToc();
35
+
36
+ # advance case
37
+ $('.toc').simpleToc({
38
+ listType: '<ol/>',
39
+ selectors: 'h1,h2,h3',
40
+ prefix: 'toc',
41
+ });
42
+ });
43
+ ```
44
+
45
+ ## Contributing
46
+
47
+ Bug reports and pull requests are welcome on GitHub at https://github.com/miraoto/simple_toc. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
48
+
49
+
50
+ ## License
51
+
52
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "simple_toc"
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
data/bin/setup ADDED
@@ -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,3 @@
1
+ module SimpleToc
2
+ VERSION = "0.1.0"
3
+ end
data/lib/simple_toc.rb ADDED
@@ -0,0 +1,8 @@
1
+ require "simple_toc/version"
2
+
3
+ module SimpleToc
4
+ module Rails
5
+ class Engine < ::Rails::Engine
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'simple_toc/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "simple_toc"
8
+ spec.version = SimpleToc::VERSION
9
+ spec.authors = ["miraoto"]
10
+ spec.email = ["miraoto@gmail.com"]
11
+
12
+ spec.summary = %q{'simple-toc' makes a simple table of contents from DOM structure.}
13
+ spec.homepage = "https://github.com/miraoto/simple_toc"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_dependency 'railties'
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.13"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
File without changes
@@ -0,0 +1,63 @@
1
+ (function($) {
2
+ $.simpleToc =function(element, options) {
3
+ var defaults = {
4
+ section: 'body',
5
+ listType: '<ul/>',
6
+ selectors: 'h2,h3',
7
+ prefix: 'toc',
8
+ anchorName: function(i, prefix) {
9
+ return prefix + '-' + i;
10
+ },
11
+ headerText: function($heading) {
12
+ return $heading.text();
13
+ },
14
+ listClass: function(i, heading, $heading, prefix) {
15
+ return prefix + '-' + $heading[0].tagName.toLowerCase();
16
+ }
17
+ }
18
+
19
+ var plugin = this;
20
+ plugin.settings = {}
21
+
22
+ var $element = $(element),
23
+ element = element;
24
+
25
+ plugin.init = function() {
26
+ plugin.settings = $.extend({}, defaults, options);
27
+
28
+ var section = $(plugin.settings.section);
29
+ var headers = $(plugin.settings.selectors, section);
30
+
31
+ return $element.each(function() {
32
+ var ul = $(plugin.settings.listType);
33
+
34
+ headers.each(function(i, header) {
35
+ console.log(header)
36
+ var $h = $(header);
37
+ var anchorName = plugin.settings.anchorName(i, plugin.settings.prefix);
38
+
39
+ if(header.id !== anchorName) {
40
+ $('<span/>').attr('id', anchorName).insertBefore($h);
41
+ }
42
+
43
+ var a = $('<a/>').text(plugin.settings.headerText($h))
44
+ .attr('href', '#' + anchorName);
45
+ var li = $('<li/>').addClass(plugin.settings.listClass(i, header, $h, plugin.settings.prefix))
46
+ .append(a);
47
+ ul.append(li);
48
+ });
49
+ $element.html(ul);
50
+ });
51
+ }
52
+ plugin.init();
53
+ }
54
+
55
+ $.fn.simpleToc = function(options) {
56
+ return this.each(function() {
57
+ if (undefined == $(this).data('simpleToc')) {
58
+ var plugin = new $.simpleToc(this, options);
59
+ $(this).data('simpleToc', plugin);
60
+ }
61
+ });
62
+ }
63
+ })(jQuery);
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple_toc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - miraoto
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-02-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: railties
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.13'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.13'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description:
56
+ email:
57
+ - miraoto@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - bin/console
68
+ - bin/setup
69
+ - lib/simple_toc.rb
70
+ - lib/simple_toc/version.rb
71
+ - simple_toc.gemspec
72
+ - vendor/assets/javascripts/.keep
73
+ - vendor/assets/javascripts/simpleToc.js
74
+ homepage: https://github.com/miraoto/simple_toc
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.6.8
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: "'simple-toc' makes a simple table of contents from DOM structure."
98
+ test_files: []