middleman-tocable 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a419145f8a1cca3407349d6e15f1cced5a4c0cd95c5a5ced8ea8533aa2fba1a0
4
+ data.tar.gz: 5539f72828c5c546649302894331f15e88781f641c604a8df14603bf97a6a225
5
+ SHA512:
6
+ metadata.gz: 0f94c59e8b08ca9c1da2175dbe81f841e17b92bebe40667b3781339fc6f0db9997ba95dc3dfcee95d51c13ab27e2926923c2daa9ce2f52fb8b407f7dca2abe6a
7
+ data.tar.gz: e3453feaaf2d919fd38e5bfbc9d6ad2727e8018975b85b19e0eb909a7a8c9e92ac4a338030e36eb11a507bbdc3e789ef9acff857e50ef50be5c035a109f7fd15
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ .idea/
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.0
7
+ before_install: gem install bundler -v 2.0.1
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at mateuyabar@mateuyabar.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in middleman-tocable.gemspec
4
+ gemspec
@@ -0,0 +1,97 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ middleman-tocable (0.0.1)
5
+ middleman-core (>= 4.0.0)
6
+ nokogiri (>= 1.10.3)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activesupport (5.0.7.1)
12
+ concurrent-ruby (~> 1.0, >= 1.0.2)
13
+ i18n (>= 0.7, < 2)
14
+ minitest (~> 5.1)
15
+ tzinfo (~> 1.1)
16
+ addressable (2.6.0)
17
+ public_suffix (>= 2.0.2, < 4.0)
18
+ backports (3.11.4)
19
+ concurrent-ruby (1.1.5)
20
+ contracts (0.13.0)
21
+ dotenv (2.6.0)
22
+ erubis (2.7.0)
23
+ execjs (2.7.0)
24
+ fast_blank (1.0.0)
25
+ fastimage (2.1.5)
26
+ ffi (1.9.25)
27
+ hamster (3.0.0)
28
+ concurrent-ruby (~> 1.0)
29
+ hashie (3.6.0)
30
+ i18n (0.9.5)
31
+ concurrent-ruby (~> 1.0)
32
+ listen (3.0.8)
33
+ rb-fsevent (~> 0.9, >= 0.9.4)
34
+ rb-inotify (~> 0.9, >= 0.9.7)
35
+ memoist (0.16.0)
36
+ middleman-core (4.3.2)
37
+ activesupport (>= 4.2, < 5.1)
38
+ addressable (~> 2.3)
39
+ backports (~> 3.6)
40
+ bundler
41
+ contracts (~> 0.13.0)
42
+ dotenv
43
+ erubis
44
+ execjs (~> 2.0)
45
+ fast_blank
46
+ fastimage (~> 2.0)
47
+ hamster (~> 3.0)
48
+ hashie (~> 3.4)
49
+ i18n (~> 0.9.0)
50
+ listen (~> 3.0.0)
51
+ memoist (~> 0.14)
52
+ padrino-helpers (~> 0.13.0)
53
+ parallel
54
+ rack (>= 1.4.5, < 3)
55
+ sassc (~> 2.0)
56
+ servolux
57
+ tilt (~> 2.0.9)
58
+ uglifier (~> 3.0)
59
+ mini_portile2 (2.4.0)
60
+ minitest (5.11.3)
61
+ nokogiri (1.10.3)
62
+ mini_portile2 (~> 2.4.0)
63
+ padrino-helpers (0.13.3.4)
64
+ i18n (~> 0.6, >= 0.6.7)
65
+ padrino-support (= 0.13.3.4)
66
+ tilt (>= 1.4.1, < 3)
67
+ padrino-support (0.13.3.4)
68
+ activesupport (>= 3.1)
69
+ parallel (1.13.0)
70
+ public_suffix (3.0.3)
71
+ rack (2.0.6)
72
+ rake (10.5.0)
73
+ rb-fsevent (0.10.3)
74
+ rb-inotify (0.10.0)
75
+ ffi (~> 1.0)
76
+ sassc (2.0.0)
77
+ ffi (~> 1.9.6)
78
+ rake
79
+ servolux (0.13.0)
80
+ thread_safe (0.3.6)
81
+ tilt (2.0.9)
82
+ tzinfo (1.2.5)
83
+ thread_safe (~> 0.1)
84
+ uglifier (3.2.0)
85
+ execjs (>= 0.3.0, < 3)
86
+
87
+ PLATFORMS
88
+ ruby
89
+
90
+ DEPENDENCIES
91
+ bundler (~> 2.0)
92
+ middleman-tocable!
93
+ minitest (~> 5.0)
94
+ rake (~> 10.0)
95
+
96
+ BUNDLED WITH
97
+ 2.0.1
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Mateu Yabar
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.
@@ -0,0 +1,46 @@
1
+ # Middleman::Tocable
2
+
3
+ Generate a TOC for a middlman site.
4
+
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'middleman-tocable'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install middleman-tocable
21
+
22
+ ## Usage
23
+
24
+ ```html
25
+ # Index
26
+ <div class="toc">
27
+ <ol>
28
+ <%
29
+ if ! defined?(toc_generation)
30
+ toc = generate_toc partial("schedule", locals: {toc_generation: true})
31
+
32
+ toc.each do |sub_item| %>
33
+ <%= partial "components/_toc_item", locals: {item: sub_item} %>
34
+ <% end
35
+ end %>
36
+ </ol>
37
+ </div>
38
+ ```
39
+
40
+ ## License
41
+
42
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
43
+
44
+ ## Code of Conduct
45
+
46
+ Everyone interacting in the Middleman::Tocable project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/middleman-tocable/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "middleman/tocable"
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(__FILE__)
@@ -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,6 @@
1
+ require "middleman-core"
2
+
3
+ Middleman::Extensions.register :tocable do
4
+ require "lib/middleman-tocable/extension"
5
+ Middleman::TocableExtension
6
+ end
@@ -0,0 +1,30 @@
1
+ # Require core library
2
+ require 'middleman-core'
3
+ require 'lib/middleman-tocable/toc_generator'
4
+
5
+ module Middleman
6
+ class TocableExtension < ::Middleman::Extension
7
+ #expose_to_template :teaching
8
+ #option :my_option, 'default', 'An example option'
9
+
10
+ def initialize(app, options_hash={}, &block)
11
+ super
12
+
13
+ # Require libraries only when activated
14
+ # require 'necessary/library'
15
+ #require 'nokogiri'
16
+
17
+ # set up your extension
18
+ # puts options.my_option
19
+ end
20
+
21
+
22
+
23
+
24
+ helpers do
25
+ def generate_toc page
26
+ Tocable::TocGenerator.new(page).toc
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,54 @@
1
+ module Middleman
2
+
3
+ module Tocable
4
+
5
+ ##
6
+ # A store of all the blog slides in the site, with accessors
7
+ # for the slides by various dimensions. Accessed via "blog" in
8
+ # templates.
9
+ ##
10
+ class TocGenerator
11
+ def initialize page
12
+ @page = page
13
+ @toc = []
14
+
15
+ generate
16
+ end
17
+
18
+ def add node
19
+ node
20
+ end
21
+
22
+ def toc
23
+ @toc
24
+ end
25
+
26
+ private
27
+
28
+ def generate
29
+ require 'nokogiri'
30
+ @current_level = 0
31
+ @current_stack = [@toc]
32
+
33
+ doc = Nokogiri::HTML(@page)
34
+ doc.search('h1, h2, h3, h4, h5, h6, h7, h8, .tocable').each do |elem|
35
+ level = (elem["data-tocable-level"] || elem.name[1]).to_i - 1
36
+ text = elem.text
37
+ id = elem.attr("id")
38
+ new_item = {id: id, text: text, items: []}
39
+ if level > @current_level
40
+ # check if jump > 1
41
+ parent = @current_stack[@current_level].last
42
+ @current_stack << parent[:items]
43
+ else
44
+ @current_stack = @current_stack[0..(level)]
45
+ parent = @current_stack.last
46
+
47
+ end
48
+ @current_level = level
49
+ @current_stack[level] << new_item
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,5 @@
1
+ module Middleman
2
+ module Tocable
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,31 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "middleman/tocable/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "middleman-tocable"
8
+ spec.version = Middleman::Tocable::VERSION
9
+ spec.authors = ["Mateu Yabar"]
10
+ spec.email = ["mateuyabar@mateuyabar.com"]
11
+
12
+ spec.summary = %q{TOC generator for Middleman.}
13
+ spec.homepage = "https://github.com/mateuyabar/middleman-tocable"
14
+ spec.license = "MIT"
15
+
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 2.0"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "minitest", "~> 5.0"
27
+
28
+ spec.add_dependency( "middleman-core", [ ">= 4.0.0" ] )
29
+ spec.add_dependency( "nokogiri", [ ">= 1.10.3" ] )
30
+
31
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: middleman-tocable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Mateu Yabar
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-05-13 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: '2.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
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: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: middleman-core
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: 4.0.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: 4.0.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: nokogiri
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 1.10.3
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 1.10.3
83
+ description:
84
+ email:
85
+ - mateuyabar@mateuyabar.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".travis.yml"
92
+ - CODE_OF_CONDUCT.md
93
+ - Gemfile
94
+ - Gemfile.lock
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - bin/console
99
+ - bin/setup
100
+ - lib/middleman/tocable.rb
101
+ - lib/middleman/tocable/extension.rb
102
+ - lib/middleman/tocable/toc_generator.rb
103
+ - lib/middleman/tocable/version.rb
104
+ - middleman-tocable.gemspec
105
+ homepage: https://github.com/mateuyabar/middleman-tocable
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.7.6
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: TOC generator for Middleman.
129
+ test_files: []