yarrow 0.4.2 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3d17bfb242d9562ef5920dae44542a59c519bf0ca6a144295017018b28d294f0
4
- data.tar.gz: 9047ab5c8c9f64203093ec60b44ba0c440f5ae24fdbdc78c4450d6d60ce5554e
3
+ metadata.gz: 30b0321a3081bb91c9f121e41e360b548eab71f03c4cbfded36709473e3cc586
4
+ data.tar.gz: 67ed41c8e4579d80e211fc08c125410b1f957adfe8e505d778020f02566efd33
5
5
  SHA512:
6
- metadata.gz: dbf90f57575402bfe1636695facae105ecdd7deb5ee46008a1f6821bedb8a7d78368e592e141537f66d2241fe6faa0a1b563fe04067bcd7e06252cd9291020cf
7
- data.tar.gz: 07fee1bb1442ae4f4b5081dee38df672e0800991f06e379f77f1e9609bdb90ff16fc958453847a3acee996b1ff3214fb66557a5bc4ca8d98156390398a3780bf
6
+ metadata.gz: fcff8cbddd540f7a44d32411c5930a70fff1a86581b5e6efdfc2e1f1eae43afa729b3f254b56581d33bcaf4d30828b2409e3129284a1ba1221823c8a26758fdb
7
+ data.tar.gz: 485752729e471a4b33f55663f8e762f8d93d1fc9ec29763a2ead843bbda1bb662b210163c723c8dc7d71111693c703e780e8c6f1394c9c317ef254461a3e8d1c
@@ -0,0 +1,23 @@
1
+ name: Ruby
2
+ on:
3
+ push:
4
+ branches: [ master ]
5
+ pull_request:
6
+ branches: [ master ]
7
+ jobs:
8
+ test:
9
+ strategy:
10
+ fail-fast: false
11
+ matrix:
12
+ os: [ubuntu-latest, macos-latest]
13
+ ruby: [2.7, '3.0', jruby]
14
+ runs-on: ${{ matrix.os }}
15
+ steps:
16
+ - uses: actions/checkout@v2
17
+ - name: Set up Ruby
18
+ uses: ruby/setup-ruby@v1
19
+ with:
20
+ ruby-version: ${{ matrix.ruby }}
21
+ bundler-cache: true
22
+ - name: Run tests
23
+ run: bundle exec rspec
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ *.tgz
2
+ fabfile.py
3
+ fabfile.pyc
4
+ pirum.xml
5
+ Gemfile.lock
6
+ yarrow-*.gem
7
+ coverage
8
+ bin/scripts
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (C) 2010-2014 by Mark Rickerby <http://maetl.net>.
2
+ All rights reserved.
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in
12
+ all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,61 @@
1
+ Yarrow
2
+ ======
3
+
4
+ [![Gem Version](http://img.shields.io/gem/v/yarrow.svg)][gem]
5
+ [![Build Status](http://img.shields.io/github/workflow/status/:user/maetl/yarrow/workflow)][github]
6
+ [![Coverage Status](http://img.shields.io/coveralls/maetl/yarrow.svg)][coveralls]
7
+
8
+ [gem]: https://rubygems.org/gems/yarrow
9
+ [github]: https://github.com/maetl/yarrow
10
+ [coveralls]: https://coveralls.io/r/maetl/yarrow
11
+
12
+ Yarrow is a tool for generating well structured documentation from a variety of input sources.
13
+
14
+ Unlike most static site generators and code documentation tools, Yarrow is written with design and content-strategy in mind. It does not impose its own structure on your content. This makes it appropriate for building static sites and blogs as well as style guides and API docs.
15
+
16
+ Installation
17
+ ------------
18
+
19
+ Install the library and command line tool via RubyGems:
20
+
21
+ ```
22
+ gem install yarrow
23
+ ```
24
+
25
+ Or embed it in an existing Ruby project by adding the following line to the `Gemfile` and running `bundle`:
26
+
27
+ ```
28
+ gem 'yarrow'
29
+ ```
30
+
31
+ Status
32
+ ------
33
+
34
+ Yarrow is an extraction from several existing private documentation projects. This repo is in alpha state, which means that many of the useful features are not yet folded into this codebase.
35
+
36
+ Yarrow is being slowly developed as a part-time project to scratch a few itches. New features and bugfixes are pushed straight to master, and releases of the Gem are kept more or less in sync with the planned roadmap.
37
+
38
+ Roadmap
39
+ -------
40
+
41
+ A rough sketch of the project direction.
42
+
43
+ | Version | Features |
44
+ |---------|----------|
45
+ | `0.3` | **[Local dev server and asset pipeline](https://github.com/maetl/yarrow/issues/48)** |
46
+ | `0.4` | Default media type mapping, collector, markup converters |
47
+ | `0.5` | Content model/object mapping, template/site context |
48
+ | `0.6` | HTML tag helpers, default layout templates |
49
+ | `0.7` | Rake integration, task library |
50
+ | `0.8` | Generic command line runner |
51
+ | `0.9` | Refactoring, performance fixes, lock down API |
52
+
53
+ License
54
+ -------
55
+
56
+ MIT. See the `LICENSE` file in the source distribution.
57
+
58
+ Contact
59
+ -------
60
+
61
+ Author: Mark Rickerby <me@maetl.net>
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ $LOAD_PATH.unshift File.expand_path("./lib", __dir__)
2
+ require "yarrow"
3
+
4
+ task :version do
5
+ puts Yarrow::VERSION
6
+ end
7
+
8
+ task :build do
9
+ sh "gem build yarrow.gemspec"
10
+ end
11
+
12
+ task :publish do
13
+ sh "gem push yarrow-#{Yarrow::VERSION}.gem"
14
+ end
15
+
16
+ task :clean do
17
+ sh "rm yarrow-*.gem"
18
+ end
data/SERVER.md ADDED
@@ -0,0 +1,41 @@
1
+ # Local Dev Server
2
+
3
+ Yarrow provides a local dev server for quick previews and incremental development of documentation.
4
+
5
+ ## Getting Started
6
+
7
+ To start the server in the current working directory, run `yarrow-server`:
8
+
9
+ ```
10
+ $ yarrow-server
11
+ ```
12
+
13
+ ## Directory Indexes
14
+
15
+ There are several options that control the behavior of directory indexes:
16
+
17
+ - `default_index` sets the name of the file used as a default directory index (usually `index.html`).
18
+ - `auto_index` generates a listing of files in the directory when no default index is provided.
19
+
20
+ ## Default Content Type
21
+
22
+ To set a default content type for files without an automatically detected MIME type or extension, use `default_type`:
23
+
24
+ ```
25
+ default_type: 'text/html'
26
+ ```
27
+
28
+ ## Rack Configuration
29
+
30
+ The following options are available under the `server` entry in the main configuration:
31
+
32
+ |Option|Type|Description|Default|
33
+ |-|-|-|-|
34
+ |**port**|Integer|Local port for the server to listen on|`8888`|
35
+ |**host**|String|Local host for the server to listen on|`localhost`|
36
+ |**handler**|Symbol (one of `:thin`, `:webrick`, etc)|Specifies the webserver implementation that handles requests|`:thin`|
37
+ |**middleware**|Array|List of Rack middleware to be injected as plugins|
38
+
39
+ Additional configuration options that are relevant:
40
+
41
+ `config.output_dir`: If specified, determines the docroot. Otherwise the server defaults to the current working directory.
data/lib/yarrow.rb CHANGED
@@ -1,20 +1,34 @@
1
1
  require 'hashie'
2
2
  require 'yaml'
3
+ require 'active_support/inflector'
3
4
 
4
5
  require 'yarrow/version'
5
6
  require 'yarrow/logging'
6
7
  require 'yarrow/configuration'
7
8
  require 'yarrow/console_runner'
8
9
  require 'yarrow/generator'
10
+ require 'yarrow/assets'
11
+ require 'yarrow/tools/front_matter'
12
+ require 'yarrow/content/graph'
13
+ require 'yarrow/content/content_type'
14
+ require 'yarrow/content/source'
15
+ require 'yarrow/content/source_collector'
16
+ require 'yarrow/content/collection_expander'
9
17
  require 'yarrow/html/asset_tags'
10
18
  require 'yarrow/output/mapper'
11
19
  require 'yarrow/output/generator'
12
20
  require 'yarrow/output/context'
13
21
  require 'yarrow/content_map'
14
22
  require 'yarrow/html'
15
- require 'yarrow/tools/front_matter'
16
23
  require 'yarrow/server'
17
24
  require 'yarrow/server/livereload'
25
+ require 'yarrow/schema'
26
+
27
+ require 'yarrow/process/workflow'
28
+ require 'yarrow/process/step_processor'
29
+ require 'yarrow/process/expand_content'
30
+ require 'yarrow/process/extract_source'
31
+ require 'yarrow/process/project_manifest'
18
32
 
19
33
  # Dir[File.dirname(__FILE__) + '/yarrow/generators/*.rb'].each do |generator|
20
34
  # require generator
@@ -0,0 +1,217 @@
1
+ module Yarrow
2
+ module Content
3
+ class CollectionExpander
4
+ include Yarrow::Tools::FrontMatter
5
+
6
+ def initialize(content_types=nil)
7
+ @content_types = content_types || [
8
+ Yarrow::Content::ContentType.from_name(:pages)
9
+ ]
10
+ end
11
+
12
+ def expand(graph)
13
+ @content_types.each do |content_type|
14
+ expand_nested(graph, content_type)
15
+ end
16
+ end
17
+
18
+ def expand_nested(graph, content_type)
19
+ type = content_type.collection
20
+ exts = content_type.extensions
21
+
22
+ # If match path represents entire content dir, then include the entire
23
+ # content dir instead of scanning from a subfolder matching the name of
24
+ # the collection.
25
+ start_node = if content_type.match_path == "."
26
+ graph.n(:root)
27
+ else
28
+ graph.n(:root).out(name: type.to_s)
29
+ end
30
+
31
+ # Extract metadata from given start node
32
+ data = extract_metadata(start_node, type)
33
+
34
+ # Collects all nested collections in the subgraph for this content type
35
+ subcollections = {}
36
+ index = nil
37
+
38
+ # Define alias for accessing metadata in the loop
39
+ metadata = data
40
+
41
+ # Scan and collect all nested directories under the top level source
42
+ start_node.depth_first.each do |node|
43
+ if node.label == :directory
44
+ # Check if this entry has metadata defined at the top level
45
+ if data[:collections]
46
+ item = data[:collections].find { |c| c[:slug] == node.props[:slug] }
47
+ metadata = item if item
48
+ end
49
+
50
+ # Create a collection node representing a collection of documents
51
+ index = graph.create_node do |collection_node|
52
+ collection_node.label = :collection
53
+ collection_node.props[:type] = type
54
+ collection_node.props[:name] = node.props[:name]
55
+ collection_node.props[:slug] = node.props[:slug]
56
+ collection_node.props[:title] = metadata[:title]
57
+
58
+ # Override default status so that mapped index collections always show
59
+ # up in the resulting document manifest, when they don’t have
60
+ # associated metadata. This is the opposite of how individual pieces
61
+ # of content behave (default to draft status if one isn’t supplied).
62
+ collection_node.props[:status] = if data[:status]
63
+ data[:status]
64
+ else
65
+ "published"
66
+ end
67
+
68
+ # TODO: URL generation might need to happen elsewhere
69
+ collection_node.props[:url] = if data[:url]
70
+ data[:url]
71
+ else
72
+ "#{node.props[:path].split('./content').last}/"
73
+ end
74
+ end
75
+
76
+ # Add this collection id to the lookup table for edge construction
77
+ subcollections[node.props[:path]] = index
78
+
79
+ # Join the collection to its parent
80
+ unless node.props[:slug] == type.to_s || !subcollections.key?(node.props[:entry].parent.to_s)
81
+ graph.create_edge do |edge|
82
+ edge.label = :child
83
+ edge.from = subcollections[node.props[:entry].parent.to_s].id
84
+ edge.to = index.id
85
+ end
86
+ end
87
+ end
88
+ end
89
+
90
+ subcollections.each do |path, index|
91
+ # Group files matching the same slug under a common key
92
+ objects = graph.n(path: path).out(:file).all.select do |file|
93
+ file.props[:name].end_with?(*exts)
94
+ end.group_by do |file|
95
+ file.props[:slug]
96
+ end
97
+
98
+ build_content_nodes(graph, objects, type, index)
99
+ end
100
+ end
101
+
102
+ # Extract collection level configuration/metadata from the root node for
103
+ # this content type.
104
+ def extract_metadata(node, type)
105
+ # TODO: support _index or _slug convention as well
106
+ meta_file = node.out(slug: type.to_s).first
107
+
108
+ if meta_file
109
+ # Process metadata and add it to the collection node
110
+ # TODO: pass in content converter object
111
+ # TODO: index/body content by default if extracted from frontmatter
112
+ body, data = process_content(meta_file.props[:entry])
113
+ else
114
+ # Otherwise, assume default collection behaviour
115
+ data = {}
116
+ end
117
+
118
+ # Generate a default title if not provided in metadata
119
+ unless data.key?(:title)
120
+ data[:title] = type.to_s.capitalize
121
+ end
122
+
123
+ data
124
+ end
125
+
126
+ def build_content_nodes(graph, objects, type, parent_index)
127
+ # TODO: this may need to use a strategy that can be overriden
128
+ content_type = ActiveSupport::Inflector.singularize(type).to_sym
129
+
130
+ # Process collected content objects and generate entity nodes
131
+ objects.each do |name, sources|
132
+ item_node = graph.create_node do |node|
133
+ # TODO: Rename this to :entry and support similar fields to Atom
134
+ node.label = :item
135
+ node.props[:name] = name
136
+ node.props[:type] = content_type
137
+
138
+ meta = {}
139
+ content = ""
140
+
141
+ sources.each do |source|
142
+ body, data = process_content(source.props[:entry])
143
+ meta.merge!(data) unless data.nil?
144
+ content << body unless body.nil?
145
+ end
146
+
147
+ if meta[:url]
148
+ # If a URL is explicitly proided in metadata then use it
149
+ node.props[:url] = meta[:url]
150
+ elsif meta[:permalink]
151
+ # Support for legacy permalink attribute
152
+ node.props[:url] = meta[:permalink]
153
+ else
154
+ # Default URL generation strategy when no explicit URL is provided
155
+ # TODO: collection nodes need URL generation too
156
+ # TODO: replace this with URL generation strategy
157
+ # TODO: slug vs name - why do some nodes have 2 and some 3 props?
158
+ node.props[:url] = if parent_index.props[:name].to_sym == parent_index.props[:type]
159
+ "/#{parent_index.props[:type]}/#{name}"
160
+ else
161
+ "/#{parent_index.props[:type]}/#{parent_index.props[:slug]}/#{name}"
162
+ end
163
+ end
164
+
165
+ # For now, we are storing title, url, etc on the top-level item.
166
+ node.props[:title] = meta[:title]
167
+
168
+ # TODO: What belongs on the entity and what belongs on the item?
169
+ entity_props = meta.merge(body: content, name: meta[:id], url: node.props[:url])
170
+
171
+
172
+ # TODO: consider whether to provide `body` on the item/document or at
173
+ # the custom content type level.
174
+ begin
175
+ content_struct = Object.const_get(ActiveSupport::Inflector.classify(content_type))
176
+ rescue
177
+ require "ostruct"
178
+ content_struct = OpenStruct
179
+ end
180
+
181
+ node.props[:entity] = content_struct.new(entity_props)
182
+ end
183
+
184
+ # Connect entity with source content
185
+ sources.each do |source|
186
+ graph.create_edge do |edge|
187
+ edge.label = :source
188
+ edge.from = item_node
189
+ edge.to = source.id
190
+ end
191
+ end
192
+
193
+ # Connect entity with parent collection
194
+ graph.create_edge do |edge|
195
+ edge.label = :child
196
+ edge.from = parent_index
197
+ edge.to = item_node
198
+ end
199
+ end
200
+ end
201
+
202
+ # Workaround for handling meta and content source in multiple files or a single
203
+ # file with front matter.
204
+ def process_content(path)
205
+ case path.extname
206
+ when '.htm', '.md'
207
+ read_split_content(path.to_s, symbolize_keys: true)
208
+ # when '.md'
209
+ # body, data = read_split_content(path.to_s, symbolize_keys: true)
210
+ # [Kramdown::Document.new(body).to_html, data]
211
+ when '.yml'
212
+ [nil, YAML.load(File.read(path.to_s), symbolize_names: true)]
213
+ end
214
+ end
215
+ end
216
+ end
217
+ end
@@ -0,0 +1,38 @@
1
+ module Yarrow
2
+ module Content
3
+ class ContentType
4
+ DEFAULT_EXTENSIONS = [".md", ".yml", ".htm"]
5
+
6
+ def self.from_name(name)
7
+ new(Yarrow::Configuration.new(collection: name.to_sym))
8
+ end
9
+
10
+ def initialize(properties)
11
+ unless properties.respond_to?(:collection) || properties.respond_to?(:entity)
12
+ raise "Must provide a collection name or entity name"
13
+ end
14
+
15
+ @properties = properties
16
+ end
17
+
18
+ def collection
19
+ return @properties.collection if @properties.respond_to?(:collection)
20
+ ActiveSupport::Inflector.pluralize(@properties.entity).to_sym
21
+ end
22
+
23
+ def entity
24
+ return @properties.entity if @properties.respond_to?(:entity)
25
+ ActiveSupport::Inflector.singularize(@properties.collection).to_sym
26
+ end
27
+
28
+ def extensions
29
+ return @properties.extensions if @properties.respond_to?(:extensions)
30
+ DEFAULT_EXTENSIONS
31
+ end
32
+
33
+ def match_path
34
+ "."
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,58 @@
1
+ require "mementus"
2
+
3
+ module Mementus
4
+ module Pipeline
5
+ class Step
6
+ # Monkeypatch extension to ensure each pipeline step supports enumerable
7
+ # methods. Mostly used for #map. API needs to be fixed in the gem itself.
8
+ include Enumerable
9
+ end
10
+ end
11
+ module Structure
12
+ class IncidenceList
13
+ def inspect
14
+ "<Mementus::Structure::IncidenceList>"
15
+ end
16
+ end
17
+ end
18
+ class Graph
19
+ def inspect
20
+ "<Mementus::Graph @structure=#{@structure.inspect} " +
21
+ "nodes_count=#{nodes_count} edges_count=#{edges_count}>"
22
+ end
23
+ end
24
+ end
25
+
26
+ module Yarrow
27
+ module Content
28
+ # A directed graph of every element of content in the project.
29
+ class Graph
30
+ # Construct a graph collected from source content files.
31
+ def self.from_source(config)
32
+ new(SourceCollector.collect(config.input_dir), config)
33
+ end
34
+
35
+ attr_reader :graph, :config
36
+
37
+ def initialize(graph, config)
38
+ @graph = graph
39
+ @config = config
40
+ end
41
+
42
+ def expand_pages
43
+ expander = Yarrow::Content::CollectionExpander.new(config.content_types)
44
+ expander.expand(graph)
45
+ end
46
+
47
+ # List of source files.
48
+ def files
49
+ graph.nodes(:file)
50
+ end
51
+
52
+ # List of source directories.
53
+ def directories
54
+ graph.nodes(:directory)
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,11 @@
1
+ module Yarrow
2
+ module Content
3
+ class Source
4
+ attr_reader :input_dir
5
+
6
+ def initialize(config)
7
+ @input_dir = config[:input_dir]
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,55 @@
1
+ module Yarrow
2
+ module Content
3
+ # Collects a digraph of all directories and files underneath the given input
4
+ # directory.
5
+ class SourceCollector
6
+ def self.collect(input_dir)
7
+ Mementus::Graph.new(is_mutable: true) do
8
+ root = create_node do |root|
9
+ root.label = :root
10
+ end
11
+
12
+ directories = {
13
+ Pathname.new(input_dir).to_s => root.id
14
+ }
15
+
16
+ Pathname.glob("#{input_dir}/**/**").each do |entry|
17
+ if entry.directory?
18
+ #puts "Reading directory: #{entry}"
19
+
20
+ content_node = create_node do |dir|
21
+ dir.label = :directory
22
+ dir.props[:name] = entry.basename.to_s
23
+ dir.props[:slug] = entry.basename.to_s
24
+ dir.props[:path] = entry.to_s
25
+ dir.props[:entry] = entry
26
+ end
27
+
28
+ directories[entry.to_s] = content_node.id
29
+ else
30
+ #puts "Reading file: #{entry} (#{entry.basename.sub_ext('')})"
31
+
32
+ content_node = create_node do |file|
33
+ file.label = :file
34
+ file.props[:name] = entry.basename.to_s
35
+ file.props[:slug] = entry.basename.sub_ext('').to_s
36
+ file.props[:path] = entry.to_s
37
+ file.props[:entry] = entry
38
+ end
39
+ end
40
+
41
+ if directories.key?(entry.dirname.to_s)
42
+ #puts "Create parent edge: #{directories[entry.dirname.to_s]}"
43
+
44
+ create_edge do |edge|
45
+ edge.label = :child
46
+ edge.from = directories[entry.dirname.to_s]
47
+ edge.to = content_node
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
@@ -1,15 +1,12 @@
1
1
  module Yarrow
2
2
  module Output
3
-
4
- ##
5
3
  # Provides a data context for rendering a template.
6
4
  #
7
- # Methods provided by this class become available as named variables in Mustache templates.
8
- #
9
- # Includes the library of helpers for dynamically generating HTML tags.
5
+ # Methods provided by this class become available as named variables in
6
+ # Mustache templates.
10
7
  #
8
+ # Includes the library of helpers for dynamically generating HTML tags.
11
9
  class Context
12
-
13
10
  include Yarrow::HTML::AssetTags
14
11
 
15
12
  def initialize(attributes)
@@ -19,6 +16,5 @@ module Yarrow
19
16
  end
20
17
  end
21
18
  end
22
-
23
19
  end
24
20
  end
@@ -0,0 +1,12 @@
1
+ module Yarrow
2
+ module Process
3
+ class ExpandContent < StepProcessor
4
+ accepts String
5
+ provides String
6
+
7
+ def step(source)
8
+ "#{source} | ExpandContent::Result"
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ module Yarrow
2
+ module Process
3
+ class ExtractSource < StepProcessor
4
+ accepts String
5
+ provides String
6
+
7
+ def step(source)
8
+ "#{source} | ExtractSource::Result"
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,20 @@
1
+ module Yarrow
2
+ module Process
3
+ class ProjectManifest < StepProcessor
4
+ accepts String
5
+ provides String
6
+
7
+ def before_step(content)
8
+
9
+ end
10
+
11
+ def step(content)
12
+ "#{content} | ProjectManifest::Result"
13
+ end
14
+
15
+ def after_step(content)
16
+
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,43 @@
1
+ module Yarrow
2
+ module Process
3
+ class StepProcessor
4
+ attr_reader :source
5
+
6
+ class << self
7
+ attr_reader :accepted_input, :provided_output
8
+
9
+ def accepts(input_const)
10
+ @accepted_input = input_const.to_s
11
+ end
12
+
13
+ def provides(output_const)
14
+ @provided_output = output_const.to_s
15
+ end
16
+ end
17
+
18
+ def initialize
19
+ @source = nil
20
+ end
21
+
22
+ def accepts
23
+ self.class.accepted_input
24
+ end
25
+
26
+ def provides
27
+ self.class.provided_output
28
+ end
29
+
30
+ def can_accept?(provided)
31
+ accepts == provided
32
+ end
33
+
34
+ def process(source)
35
+ # begin
36
+ result = step(source)
37
+ # log.info("<Result source=#{result}>")
38
+ # rescue
39
+ result
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,36 @@
1
+ module Yarrow
2
+ module Process
3
+ class Workflow
4
+ def initialize(input)
5
+ @input = input
6
+ @processors = []
7
+ end
8
+
9
+ def connect(processor)
10
+ provided_input = if @processors.any?
11
+ @processors.last.provides
12
+ else
13
+ @input.class.to_s
14
+ end
15
+
16
+ if processor.can_accept?(provided_input)
17
+ @processors << processor
18
+ else
19
+ raise ArgumentError.new(
20
+ "`#{processor.class}` accepts `#{processor.accepts}` but was connected to `#{provided_input}`"
21
+ )
22
+ end
23
+ end
24
+
25
+ def process(&block)
26
+ result = @input
27
+
28
+ @processors.each do |processor|
29
+ result = processor.process(result)
30
+ end
31
+
32
+ block.call(result)
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,120 @@
1
+ module Yarrow
2
+ module Schema
3
+ module Type
4
+ class Any
5
+ end
6
+ end
7
+
8
+ ##
9
+ # Checks values plugged into each slot and runs any required validations
10
+ # (validations not yet implemented).
11
+ #
12
+ # Current design throws on error rather than returns a boolean result.
13
+ class Validator
14
+ # @param fields_spec [Hash] defines the slots in the schema to validate against
15
+ def initialize(fields_spec)
16
+ @spec = fields_spec
17
+ end
18
+
19
+ def check(fields)
20
+ raise "wrong number of args" unless fields.keys.length == @spec.keys.length
21
+
22
+ fields.keys.each do |key|
23
+ raise "key does not exist" unless @spec.key?(key)
24
+ end
25
+ end
26
+ end
27
+
28
+ ##
29
+ # Value object (with comparison by value equality). This just chucks back a
30
+ # Ruby struct but wraps the constructor with method advice that handles
31
+ # validation (and eventually type coercion if !yagni).
32
+ class Value
33
+ def self.new(*slots, **fields, &block)
34
+ factory(*slots, **fields, &block)
35
+ end
36
+
37
+ def self.factory(*slots, **fields, &block)
38
+ if slots.empty? && fields.empty?
39
+ raise ArgumentError.new("missing attribute definition")
40
+ end
41
+
42
+ slots_spec, fields_spec = if fields.any?
43
+ raise ArgumentError.new("cannot use slots when field map is supplied") if slots.any?
44
+ [fields.keys, fields]
45
+ else
46
+ [slots, Hash[slots.map { |s| [s, Type::Any]}]]
47
+ end
48
+
49
+ validator = Validator.new(fields_spec)
50
+
51
+ struct = Struct.new(*slots_spec, keyword_init: true, &block)
52
+
53
+ struct.define_method :initialize do |*args, **kwargs|
54
+ attr_values = if args.any?
55
+ raise ArgumentError.new("cannot mix slots and kwargs") if kwargs.any?
56
+ Hash[slots.zip(args)]
57
+ else
58
+ kwargs
59
+ end
60
+
61
+ validator.check(attr_values)
62
+ # TODO: type coercion or mapping decision goes here
63
+ super(**attr_values)
64
+
65
+ freeze
66
+ end
67
+
68
+ struct
69
+ end
70
+ end
71
+
72
+ ##
73
+ # Entity with comparison by reference equality. Generates attribute helpers
74
+ # for a declared set of props. Used to replace Hashie::Mash without dragging
75
+ # in a whole new library.
76
+ class Entity
77
+ class << self
78
+ def attribute(name, value_type)
79
+ # define_method("map_#{name}".to_sym) do |input|
80
+ # value_type.coerce(input)
81
+ # end
82
+ dictionary[name] = value_type
83
+ attr_reader(name)
84
+ end
85
+
86
+ def dictionary
87
+ @dictionary ||= Hash.new
88
+ end
89
+ end
90
+
91
+ def dictionary
92
+ self.class.dictionary
93
+ end
94
+
95
+ def initialize(config)
96
+ dictionary.each_key do |name|
97
+ raise "missing declared attribute #{name}" unless dictionary.key?(name)
98
+ end
99
+
100
+ config.each_pair do |key, value|
101
+ raise "#{key} not a declared attribute" unless dictionary.key?(key)
102
+
103
+ defined_type = dictionary[key]
104
+
105
+ unless value.is_a?(defined_type)
106
+ raise "#{key} accepts #{defined_type} but #{value.class} given"
107
+ end
108
+
109
+ instance_variable_set("@#{key}", value)
110
+ end
111
+ end
112
+ end
113
+
114
+ def to_h
115
+ dictionary.keys.reduce({}) do |h, name|
116
+ h[name] = instance_variable_get("@#{name}")
117
+ end
118
+ end
119
+ end
120
+ end
File without changes
File without changes
File without changes
data/lib/yarrow/server.rb CHANGED
@@ -16,6 +16,7 @@ module Yarrow
16
16
  # Rack Middleware for detecting and serving an 'index.html' file
17
17
  # instead of a directory index.
18
18
  #
19
+ # TODO: Fix bug where a directory /index.html/ causes this to crash
19
20
  # TODO: Add configurable mapping and media types for README files as an alternative
20
21
  class DirectoryIndex
21
22
  def initialize(app, options={})
@@ -0,0 +1,6 @@
1
+ module Yarrow
2
+ module Source
3
+ class Graph
4
+ end
5
+ end
6
+ end
@@ -13,7 +13,7 @@ module Yarrow
13
13
 
14
14
  begin
15
15
  if options.key?(:symbolize_keys)
16
- meta = symbolize_keys(YAML.load($1))
16
+ meta = YAML.load($1, symbolize_names: true)
17
17
  else
18
18
  meta = YAML.load($1)
19
19
  end
@@ -30,22 +30,6 @@ module Yarrow
30
30
 
31
31
  [text, nil]
32
32
  end
33
-
34
- def symbolize_keys(hash)
35
- hash.inject({}) do |result, (key, value)|
36
- new_key = case key
37
- when String then key.to_sym
38
- else key
39
- end
40
- new_value = case value
41
- when Hash then symbolize_keys(value)
42
- when Array then value.map { |entry| symbolize_keys(entry) }
43
- else value
44
- end
45
- result[new_key] = new_value
46
- result
47
- end
48
- end
49
33
  end
50
34
  end
51
35
  end
@@ -1,4 +1,5 @@
1
+ # frozen_string_literal: true
1
2
  module Yarrow
2
- APP_NAME = 'Yarrow'.freeze
3
- VERSION = '0.4.2'.freeze
3
+ APP_NAME = 'Yarrow'
4
+ VERSION = '0.6.1'
4
5
  end
@@ -0,0 +1,9 @@
1
+ module Yarrow
2
+ module Web
3
+ class HTMLDocument
4
+ def initialize
5
+
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Yarrow
2
+ module Web
3
+ class Manifest
4
+ def initialize
5
+
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Yarrow
2
+ module Web
3
+ class StaticAsset
4
+ def initialize
5
+
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Yarrow
2
+ module Web
3
+ class Template
4
+ def initialize
5
+
6
+ end
7
+ end
8
+ end
9
+ end
data/yarrow.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ $:.push File.expand_path('../lib', __FILE__)
2
+
3
+ require 'yarrow/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'yarrow'
7
+ spec.version = Yarrow::VERSION
8
+ spec.platform = Gem::Platform::RUBY
9
+ spec.summary = 'Documentation generator based on a fluent data model.'
10
+ spec.description = 'Yarrow is a tool for generating well structured documentation from a variety of input sources.'
11
+ spec.authors = ['Mark Rickerby']
12
+ spec.email = 'me@maetl.net'
13
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
14
+ spec.executables << 'yarrow'
15
+ spec.executables << 'yarrow-server'
16
+ spec.add_runtime_dependency 'hashie', '~> 3.5'
17
+ spec.add_runtime_dependency 'mementus', '~> 0.8'
18
+ spec.add_runtime_dependency 'activesupport', '~> 5.1'
19
+ spec.add_runtime_dependency 'rack', '~> 2.0'
20
+ spec.add_runtime_dependency 'rack-livereload', '~> 0.3'
21
+ spec.add_runtime_dependency 'eventmachine', '~> 1.2'
22
+ spec.add_runtime_dependency 'em-websocket', '~> 0.5.1'
23
+ spec.add_runtime_dependency 'sprockets', '~> 3.7'
24
+ spec.add_development_dependency 'bundler', '~> 2.2.9'
25
+ spec.add_development_dependency 'rake', '~> 13.0'
26
+ spec.add_development_dependency 'rspec', '~> 3.10'
27
+ spec.add_development_dependency 'coveralls', '~> 0.8.23'
28
+ spec.add_development_dependency 'rack-test', '~> 0.8'
29
+ spec.homepage = 'http://rubygemspec.org/gems/yarrow'
30
+ spec.license = 'MIT'
31
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yarrow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Rickerby
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-02 00:00:00.000000000 Z
11
+ date: 2021-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashie
@@ -108,62 +108,76 @@ dependencies:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: 0.5.1
111
+ - !ruby/object:Gem::Dependency
112
+ name: sprockets
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '3.7'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '3.7'
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: bundler
113
127
  requirement: !ruby/object:Gem::Requirement
114
128
  requirements:
115
129
  - - "~>"
116
130
  - !ruby/object:Gem::Version
117
- version: '1.16'
131
+ version: 2.2.9
118
132
  type: :development
119
133
  prerelease: false
120
134
  version_requirements: !ruby/object:Gem::Requirement
121
135
  requirements:
122
136
  - - "~>"
123
137
  - !ruby/object:Gem::Version
124
- version: '1.16'
138
+ version: 2.2.9
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: rake
127
141
  requirement: !ruby/object:Gem::Requirement
128
142
  requirements:
129
143
  - - "~>"
130
144
  - !ruby/object:Gem::Version
131
- version: '12.3'
145
+ version: '13.0'
132
146
  type: :development
133
147
  prerelease: false
134
148
  version_requirements: !ruby/object:Gem::Requirement
135
149
  requirements:
136
150
  - - "~>"
137
151
  - !ruby/object:Gem::Version
138
- version: '12.3'
152
+ version: '13.0'
139
153
  - !ruby/object:Gem::Dependency
140
154
  name: rspec
141
155
  requirement: !ruby/object:Gem::Requirement
142
156
  requirements:
143
157
  - - "~>"
144
158
  - !ruby/object:Gem::Version
145
- version: '3.7'
159
+ version: '3.10'
146
160
  type: :development
147
161
  prerelease: false
148
162
  version_requirements: !ruby/object:Gem::Requirement
149
163
  requirements:
150
164
  - - "~>"
151
165
  - !ruby/object:Gem::Version
152
- version: '3.7'
166
+ version: '3.10'
153
167
  - !ruby/object:Gem::Dependency
154
168
  name: coveralls
155
169
  requirement: !ruby/object:Gem::Requirement
156
170
  requirements:
157
171
  - - "~>"
158
172
  - !ruby/object:Gem::Version
159
- version: '0.8'
173
+ version: 0.8.23
160
174
  type: :development
161
175
  prerelease: false
162
176
  version_requirements: !ruby/object:Gem::Requirement
163
177
  requirements:
164
178
  - - "~>"
165
179
  - !ruby/object:Gem::Version
166
- version: '0.8'
180
+ version: 0.8.23
167
181
  - !ruby/object:Gem::Dependency
168
182
  name: rack-test
169
183
  requirement: !ruby/object:Gem::Requirement
@@ -187,6 +201,13 @@ executables:
187
201
  extensions: []
188
202
  extra_rdoc_files: []
189
203
  files:
204
+ - ".github/workflows/ruby.yml"
205
+ - ".gitignore"
206
+ - Gemfile
207
+ - LICENSE
208
+ - README.md
209
+ - Rakefile
210
+ - SERVER.md
190
211
  - bin/yarrow
191
212
  - bin/yarrow-server
192
213
  - lib/yarrow.rb
@@ -195,6 +216,11 @@ files:
195
216
  - lib/yarrow/assets/pipeline.rb
196
217
  - lib/yarrow/configuration.rb
197
218
  - lib/yarrow/console_runner.rb
219
+ - lib/yarrow/content/collection_expander.rb
220
+ - lib/yarrow/content/content_type.rb
221
+ - lib/yarrow/content/graph.rb
222
+ - lib/yarrow/content/source.rb
223
+ - lib/yarrow/content/source_collector.rb
198
224
  - lib/yarrow/content_map.rb
199
225
  - lib/yarrow/defaults.yml
200
226
  - lib/yarrow/generator.rb
@@ -205,11 +231,26 @@ files:
205
231
  - lib/yarrow/output/context.rb
206
232
  - lib/yarrow/output/generator.rb
207
233
  - lib/yarrow/output/mapper.rb
234
+ - lib/yarrow/process/expand_content.rb
235
+ - lib/yarrow/process/extract_source.rb
236
+ - lib/yarrow/process/project_manifest.rb
237
+ - lib/yarrow/process/step_processor.rb
238
+ - lib/yarrow/process/workflow.rb
239
+ - lib/yarrow/schema.rb
240
+ - lib/yarrow/schema/validations/array.rb
241
+ - lib/yarrow/schema/validations/object.rb
242
+ - lib/yarrow/schema/validations/string.rb
208
243
  - lib/yarrow/server.rb
209
244
  - lib/yarrow/server/livereload.rb
245
+ - lib/yarrow/source/graph.rb
210
246
  - lib/yarrow/tools/front_matter.rb
211
247
  - lib/yarrow/tools/output_file.rb
212
248
  - lib/yarrow/version.rb
249
+ - lib/yarrow/web/html_document.rb
250
+ - lib/yarrow/web/manifest.rb
251
+ - lib/yarrow/web/static_asset.rb
252
+ - lib/yarrow/web/template.rb
253
+ - yarrow.gemspec
213
254
  homepage: http://rubygemspec.org/gems/yarrow
214
255
  licenses:
215
256
  - MIT
@@ -229,8 +270,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
229
270
  - !ruby/object:Gem::Version
230
271
  version: '0'
231
272
  requirements: []
232
- rubyforge_project:
233
- rubygems_version: 2.7.6
273
+ rubygems_version: 3.1.2
234
274
  signing_key:
235
275
  specification_version: 4
236
276
  summary: Documentation generator based on a fluent data model.