awestruct-ibeams 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6efd8c9c2adb0cbc709e972e9ac6c1cc4f6802d4
4
+ data.tar.gz: c342e9ca8b1e008fe8bb905beebc9c45cb12e5e5
5
+ SHA512:
6
+ metadata.gz: 99d3cdb7d7171d39810e701263f59e87fbe98e3a59203eb0b72a87d0485f3c8dda451795b9444cc57fa0ff1a746738b21ce477d648ca8e4c423182c9750f5c3c
7
+ data.tar.gz: 706e50e140035860e98d2cb2bde1cd4fa73d0e116a5088bbdb444265981e216c4fcefb642441542eba0f8b4ed7f2c8240611b2e727015d7436e43d6fe34741d9
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .ruby-*
11
+ *.sw*
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in awestruct-ibeams.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem 'rake', '~> 10.0'
8
+ gem 'pry'
9
+ gem 'rspec'
10
+ gem 'rspec-its'
11
+ end
data/LICENSE.adoc ADDED
@@ -0,0 +1,28 @@
1
+ = License
2
+
3
+ == Code
4
+
5
+ This license applies code contributed to this repository
6
+
7
+ .MIT License
8
+ ""
9
+ Copyright (c) 2015-2016 CloudBees, Inc, and respective contributors
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
12
+ this software and associated documentation files (the "Software"), to deal in
13
+ the Software without restriction, including without limitation the rights to
14
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
15
+ of the Software, and to permit persons to whom the Software is furnished to do
16
+ so, subject to the following conditions:
17
+
18
+ The above copyright notice and this permission notice shall be included in all
19
+ copies or substantial portions of the Software.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ SOFTWARE.
28
+ ""
data/README.adoc ADDED
@@ -0,0 +1,30 @@
1
+ = Awestruct I-Beams
2
+
3
+ The `awestruct-ibeams` gem adds more structural support with a variety of
4
+ different extensions to the link:http://awestruct.org[Awestruct] static site
5
+ generator.
6
+
7
+
8
+ == Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ [source, ruby]
13
+ ----
14
+ gem 'awestruct-ibeams'
15
+ ----
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install awestruct-ibeams
24
+
25
+ == Usage
26
+
27
+ == Contributing
28
+
29
+ Bug reports and pull requests are welcome
30
+ link:https://github.com/jenkins-infra/awestruct-ibeams[on GitHub].
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+
8
+ task :default => [:spec, :build]
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'awestruct/ibeams/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "awestruct-ibeams"
8
+ spec.version = Awestruct::Ibeams::VERSION
9
+ spec.authors = ["R. Tyler Croy"]
10
+ spec.email = ["tyler@monkeypox.org"]
11
+
12
+ spec.summary = "Collection of helpful Awestruct extensions and helpers"
13
+ spec.description = "Collection of helpful Awestruct extensions and helpers"
14
+ spec.homepage = 'https://github.com/jenkins-infra/awestruct-ibeams'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'awestruct', '~> 0.5.6'
22
+ end
@@ -0,0 +1,99 @@
1
+ require 'asciidoctor'
2
+ require 'awestruct/ibeams/errors'
3
+
4
+ module Awestruct
5
+ module IBeams
6
+ module AsciidocSections
7
+ # sections_from() will take the given
8
+ #
9
+ # @param [String] relative or absolute path to a directory containing
10
+ # asciidoc files (`.ad`, `.adoc`)
11
+ # @return [Array] Array of arrays containing: [section_title, filepath,
12
+ # link_to_section, subsections]
13
+ # @raise [Errors::InvalidPath] thrown when the provided +directory+ is
14
+ # not a valid path to an existing directory
15
+ def sections_from(directory)
16
+ if directory.nil?
17
+ raise Errors::InvalidPath.new("The provided `directory` was nil")
18
+ end
19
+ unless File.directory?(directory)
20
+ raise Errors::InvalidPath.new("The provided `#{directory}` is not a valid directory")
21
+ end
22
+
23
+ # Generate a +Hash+ of all the pages in the site keyed by their path
24
+ # for easy discovery
25
+ pages_by_path = site.pages.map { |p| [p.source_path, p] }.to_h
26
+ sections = []
27
+
28
+ Dir.glob(File.join(directory, "*.{ad,adoc}")).sort.each do |adoc|
29
+ # Since all our documents are going to have front-matter so they render
30
+ # properly, we need to look first at the Awestruct::Page and then
31
+ # re-render to grab the sections from the asciidoc
32
+ page = pages_by_path[adoc]
33
+ url = page.url
34
+
35
+ document = Asciidoctor.load(page.raw_content)
36
+
37
+ document.sections.each do |section|
38
+ sections << [
39
+ section.title,
40
+ adoc,
41
+ url,
42
+ find_subsections_from(section, document)
43
+ ]
44
+ end
45
+ end
46
+
47
+ return sections
48
+ end
49
+
50
+
51
+ # This method will recurse through all the subsections of the given
52
+ # +section+ to discover the full tree of subsections and compute a nested
53
+ # array containing them.
54
+ #
55
+ # @param [Asciidoctor::Section] section to discover subsections from
56
+ # @param [Asciidoctor::Document] Document objection the section anchor
57
+ # belongs to, this is necessary to ensure the document's settinsg are
58
+ # used to provide the appropriate anchors
59
+ # @return [Array] of subsection arrays
60
+ def find_subsections_from(section, in_document)
61
+ found = []
62
+
63
+ section.sections.each do |subsection|
64
+ title = subsection.title
65
+ found << [
66
+ title,
67
+ in_document.file,
68
+ section_anchor(title, in_document),
69
+ find_subsections_from(subsection, in_document),
70
+ ]
71
+ end
72
+
73
+ return found
74
+ end
75
+
76
+
77
+ # Compute an appropriate section anchor for the given title within the
78
+ # given +Asciidoctor::Document+. This is effectively the same logic that
79
+ # Asciidoctor itself inside the +Asciidoctor::Section#generate_id+ method
80
+ # but extracted to be callable in an idempotent fashion
81
+ #
82
+ # @param [String] title of the section provided
83
+ # @param [Asciidoctor::Document] Document objection the section anchor
84
+ # belongs to, this is necessary to ensure the document's settinsg are
85
+ # used to provide the appropriate anchor
86
+ # @return [String] Computed section anchor
87
+ def section_anchor(title, in_document)
88
+ prefix = in_document.attributes['idprefix'] || ''
89
+ separator = in_document.attributes['idseparator'] || '-'
90
+ title = title.downcase.gsub(Asciidoctor::InvalidSectionIdCharsRx, separator)
91
+
92
+ return [
93
+ prefix,
94
+ title.tr_s(separator, separator).chomp(separator),
95
+ ].join('')
96
+ end
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,21 @@
1
+ require 'awestruct/extensions/partial'
2
+
3
+ module Awestruct
4
+ module IBeams
5
+ # Debuggbale partial is just like a regular partial in awestruct except
6
+ # there are HTML comments which make it clearer which files are being
7
+ # included where in the rendered output
8
+ module DebuggablePartial
9
+ include Awestruct::Extensions::Partial
10
+ alias_method :original_partial, :partial
11
+
12
+ def partial(path, params={})
13
+ return [
14
+ "<!-- starting partial #{path} -->",
15
+ original_partial(path, params),
16
+ "<!-- ending partial #{path} -->",
17
+ ].join("\n")
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,8 @@
1
+
2
+ module Awestruct
3
+ module IBeams
4
+ module Errors
5
+ class InvalidPath < Exception; end;
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ module Awestruct
2
+ module Ibeams
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ require "awestruct/ibeams/version"
2
+
3
+ module Awestruct
4
+ module Ibeams
5
+ # Your code goes here...
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: awestruct-ibeams
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - R. Tyler Croy
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-03-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: awestruct
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.5.6
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.5.6
27
+ description: Collection of helpful Awestruct extensions and helpers
28
+ email:
29
+ - tyler@monkeypox.org
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - Gemfile
36
+ - LICENSE.adoc
37
+ - README.adoc
38
+ - Rakefile
39
+ - awestruct-ibeams.gemspec
40
+ - lib/awestruct/ibeams.rb
41
+ - lib/awestruct/ibeams/asciidoc_sections.rb
42
+ - lib/awestruct/ibeams/debuggable_partial.rb
43
+ - lib/awestruct/ibeams/errors.rb
44
+ - lib/awestruct/ibeams/version.rb
45
+ homepage: https://github.com/jenkins-infra/awestruct-ibeams
46
+ licenses: []
47
+ metadata: {}
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirements: []
63
+ rubyforge_project:
64
+ rubygems_version: 2.5.0
65
+ signing_key:
66
+ specification_version: 4
67
+ summary: Collection of helpful Awestruct extensions and helpers
68
+ test_files: []