marko 0.3.0 → 0.4.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.
Files changed (119) hide show
  1. checksums.yaml +4 -4
  2. data/.dockerignore +12 -0
  3. data/.rubocop.yml +45 -0
  4. data/CHANGELOG.md +10 -4
  5. data/Dockerfile +11 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +17 -31
  8. data/Rakefile +2 -11
  9. data/exe/marko +4 -22
  10. data/lib/basic.rb +27 -0
  11. data/lib/marko/chain.rb +44 -0
  12. data/lib/marko/cli.rb +119 -129
  13. data/lib/marko/config.rb +30 -20
  14. data/lib/marko/errors.rb +38 -0
  15. data/lib/marko/model/markup.rb +33 -0
  16. data/lib/marko/model/topic.rb +126 -0
  17. data/lib/marko/model/tree_node.rb +34 -0
  18. data/lib/marko/model.rb +10 -0
  19. data/lib/marko/parser/metadata.rb +28 -0
  20. data/lib/marko/parser/source.rb +52 -0
  21. data/lib/marko/parser/topic.rb +33 -0
  22. data/lib/marko/parser.rb +8 -19
  23. data/lib/marko/renderers/artifact.rb +29 -0
  24. data/lib/marko/renderers/content.rb +37 -0
  25. data/lib/marko/renderers/link.rb +19 -0
  26. data/lib/marko/renderers/metadata.rb +34 -0
  27. data/lib/marko/renderers/nested_list.rb +21 -0
  28. data/lib/marko/renderers/nested_tree.rb +22 -0
  29. data/lib/marko/renderers/renderer.rb +17 -0
  30. data/lib/marko/renderers/title.rb +16 -0
  31. data/lib/marko/renderers/topic.rb +24 -0
  32. data/lib/marko/renderers/url.rb +16 -0
  33. data/lib/marko/renderers.rb +17 -0
  34. data/lib/marko/scanner.rb +39 -0
  35. data/lib/marko/tasks/assemble.rb +52 -0
  36. data/lib/marko/tasks/compile.rb +19 -0
  37. data/lib/marko/tasks/load.rb +13 -0
  38. data/lib/marko/tasks/parse.rb +27 -0
  39. data/lib/marko/tasks/scan.rb +18 -0
  40. data/lib/marko/tasks/validate.rb +32 -0
  41. data/lib/marko/tasks.rb +13 -0
  42. data/lib/marko/validators/lost_index.rb +21 -0
  43. data/lib/marko/validators/lost_links.rb +25 -0
  44. data/lib/marko/validators/lost_parent.rb +21 -0
  45. data/lib/marko/validators/non_unique_id.rb +23 -0
  46. data/lib/marko/validators.rb +11 -0
  47. data/lib/marko/version.rb +1 -3
  48. data/lib/marko.rb +11 -43
  49. metadata +47 -85
  50. data/Gemfile +0 -10
  51. data/Gemfile.lock +0 -23
  52. data/STORY.md +0 -44
  53. data/_layouts/footer.md +0 -4
  54. data/_layouts/header.md +0 -3
  55. data/_layouts/layout.html +0 -73
  56. data/_layouts/robots.txt.erb +0 -4
  57. data/_layouts/sitemap.xml.erb +0 -20
  58. data/_layouts/styles.css +0 -92
  59. data/docs/changelog.html +0 -74
  60. data/docs/css/styles.css +0 -92
  61. data/docs/index.html +0 -297
  62. data/docs/readme.html +0 -297
  63. data/docs/robots.txt +0 -4
  64. data/docs/sitemap.xml +0 -30
  65. data/docs/story.html +0 -132
  66. data/lib/assets/demo/README.md +0 -13
  67. data/lib/assets/demo/src/fr/assemble.md +0 -27
  68. data/lib/assets/demo/src/fr/compile.md +0 -25
  69. data/lib/assets/demo/src/fr/markup.md +0 -111
  70. data/lib/assets/demo/src/fr/storage.md +0 -16
  71. data/lib/assets/demo/src/fr/treenode.md +0 -34
  72. data/lib/assets/demo/src/index.md +0 -34
  73. data/lib/assets/demo/src/intro.md +0 -98
  74. data/lib/assets/demo/src/ui/cli.md +0 -26
  75. data/lib/assets/demo/src/ui/gem.md +0 -14
  76. data/lib/assets/demo/src/ur/uc.create.project.md +0 -8
  77. data/lib/assets/demo/src/ur/uc.general.flow.md +0 -14
  78. data/lib/assets/init/README.md +0 -61
  79. data/lib/assets/init/Rakefile +0 -100
  80. data/lib/assets/init/tt/custom.md.tt +0 -19
  81. data/lib/assets/init/tt/default.md.tt +0 -4
  82. data/lib/assets/samples/0_index.md +0 -14
  83. data/lib/assets/samples/1_intro.md +0 -55
  84. data/lib/assets/samples/2_stakh.md +0 -21
  85. data/lib/assets/samples/3_actors.md +0 -10
  86. data/lib/assets/samples/4_cases.md +0 -53
  87. data/lib/assets/samples/5_entities.md +0 -18
  88. data/lib/assets/samples/6_concerns.md +0 -60
  89. data/lib/assets/samples/SRS-IEEE-830-1998.md +0 -293
  90. data/lib/assets/samples/SRS-RUP.md +0 -283
  91. data/lib/assets/samples/business-case.md +0 -116
  92. data/lib/assets/samples/ears.md +0 -112
  93. data/lib/assets/samples/gen_punch_domain.rb +0 -183
  94. data/lib/assets/samples/requirements.md +0 -105
  95. data/lib/assets/samples/stakeholders.png +0 -0
  96. data/lib/assets/samples/vision.md +0 -191
  97. data/lib/marko/artifact.rb +0 -5
  98. data/lib/marko/assembler.rb +0 -83
  99. data/lib/marko/compiler.rb +0 -16
  100. data/lib/marko/gadgets/pluggable.rb +0 -55
  101. data/lib/marko/gadgets/sentry.rb +0 -66
  102. data/lib/marko/gadgets/service.rb +0 -52
  103. data/lib/marko/gadgets.rb +0 -3
  104. data/lib/marko/loader.rb +0 -38
  105. data/lib/marko/markup/compiler.rb +0 -30
  106. data/lib/marko/markup/decorator.rb +0 -80
  107. data/lib/marko/markup/macro.rb +0 -176
  108. data/lib/marko/markup/parser.rb +0 -122
  109. data/lib/marko/markup/storage.rb +0 -118
  110. data/lib/marko/markup/validator.rb +0 -101
  111. data/lib/marko/markup.rb +0 -24
  112. data/lib/marko/services/assemble.rb +0 -16
  113. data/lib/marko/services/compile.rb +0 -30
  114. data/lib/marko/services.rb +0 -2
  115. data/lib/marko/storage.rb +0 -36
  116. data/lib/marko/tree_node.rb +0 -129
  117. data/lib/marko/validator.rb +0 -19
  118. data/marko.gemspec +0 -44
  119. data/sancho.yml +0 -6
@@ -1,191 +0,0 @@
1
- % Vision Document Template
2
- Company Name
3
- Vision Document for [Program Name]
4
- (r) 20XX [Company Name]
5
-
6
- # Revision History
7
-
8
- Date | Revision | Description | Author
9
- :--- | :------- | :---------- | :-----
10
- mm/dd/yy | 1.0 | Initial version | Author name
11
-
12
- # Table of Contents
13
-
14
- # 1 Introduction
15
-
16
- This section provides an overview of the Vision document.
17
-
18
- ## 1.1 Purpose
19
-
20
- This document defines the strategic intent of the program. It defines high-level user needs, any applicable user personas, key stakeholders, and the general system capabilities needed by the users.
21
-
22
- ## 1.2 Solution Overview
23
-
24
- State the general purpose of the product, system, application or service, and any version identification.
25
-
26
- * Identify the product or application to be created or enhanced.
27
- * Describe the application of the product, including its benefits, goals, and objectives.
28
- * Provide a general description of what the solution will and, where appropriate, will not do.
29
-
30
- ## 1.3 References
31
-
32
- List other documents referenced, and specify the sources from which the references can be obtained. If a business case (Chapter 23) was developed to drive the program, refer to it or attach it.
33
-
34
- # 2 User Description
35
- To provide products and services that meet users’ needs, it is helpful to understand the challenges they confront when performing their jobs. This section should profile the intended users of the application and the key problems that limit the user’s productivity. This section should not be used to state specific requirements; just provide the background for why the features specified in Section 5 are needed.
36
-
37
- ## 2.1 User/Market Demographics
38
-
39
- Summarize the key market demographics that motivate your solution decisions. Describe target-market segments. Estimate the market’s size and growth by the number of potential users or the amount of money your customers spend, trying to meet needs that your product/enhancement would fulfill. Review major industry trends and technologies. Refer to a market analysis, where available.
40
-
41
- ## 2.2 User Personas
42
-
43
- Describe the primary and secondary user personas (see Chapter 7). A thorough analysis might cover the following topics for each persona:
44
-
45
- * Technical background and degree of sophistication
46
- * Key responsibilities
47
- * Deliverables the user produces and for whom
48
- * Trends that make the user’s job easier or more difficult
49
- * The user’s definition of success and how the user is rewarded
50
- * Problems that interfere with success
51
-
52
- ## 2.3 User Environment
53
-
54
- Describe the working environment of the target user. Here are some suggestions.
55
-
56
- * How many people are involved in completing the task? Is this changing?
57
- * How long is a task cycle? How much time is spent in each activity? Is this changing?
58
- * Are there any unique environmental constraints: controlled environment, mobile, outdoors, and so on?
59
- * Which system platforms are in use today? Future platforms?
60
- * What other applications are in use? Does your application need to integrate with them?
61
-
62
- ## 2.4 Key User Needs
63
-
64
- List the key problems or needs as perceived by the user. Clarify the following issues for each problem.
65
-
66
- * What are the reasons for this problem?
67
- * How is it solved now?
68
- * What solutions does the user envision?
69
-
70
- Ranking and cumulative-voting techniques for these needs indicate problems that must be solved versus issues the user would like to be solved.
71
-
72
- ## 2.5 Alternatives and Competition
73
-
74
- Identify any alternatives available to the user. These can include buying a competitor’s product, building a homegrown solution, or simply maintaining the status quo. List any known competitive choices that exist. Include the major strengths and weaknesses of each competitor as perceived by the end user.
75
-
76
- ### 2.5.1 Competitor 1
77
-
78
- ### 2.5.2 Competitor 2
79
-
80
- # 3 Stakeholders
81
-
82
- Identify the program stakeholders, their needs, and their degree of involvement with the system. A table such as the following can be effective:
83
-
84
- Project<br/>Stakeholder | Degree of<br/> Involvement | Product Needs | Program Needs
85
- :---- | :---- | :---- | :----
86
- Stakeholder 1 | | |
87
- Stakeholder 2 | | |
88
-
89
- # 4 Product Overview
90
-
91
- This section provides a high-level view of the solution capabilities, interfaces to other applications, and systems configurations. This section usually consists of five subsections, as follows.
92
-
93
- ## 4.1 Product Perspective
94
-
95
- This subsection should put the product in perspective to other related products and the user’s environment. If the product is independent and totally self-contained, state so. If the product is a component of a larger system, this subsection should relate how these systems interact and should identify the relevant interfaces among the systems. One easy way to display the major components of the larger system, interconnections, and external interfaces is via a system context block diagram.
96
-
97
- ## 4.2 Product Position Statement
98
-
99
- Provide an overall statement summarizing, at the highest level, the unique position the product intends to fill in the marketplace. Moore [1991] calls this the product position statement and recommends the following format.
100
-
101
- For | (target customer)
102
- :-- | :----------------
103
- Who | (statement of the need or opportunity)
104
- The (product name) | is a (product category)
105
- That | (statement of key benefit, that is, compelling rea
106
- son to buy)
107
- Unlike | (primary competitive alternative)
108
- Our product | (statement of primary differentiation)
109
-
110
- A product position statement communicates the intent of the application and the importance of the program to all stakeholders.
111
-
112
- ## 4.3 Summary of Capabilities
113
-
114
- Summarize the major benefits and features the product will provide. Organize the features so that the list is understandable to any stakeholder. A simple table listing the key benefits and their supporting features, as shown below, might suffice.
115
-
116
- Solution Features | Customer Benefit
117
- :---------------- | :---------------
118
- Feature 1 | Benefit 1
119
- Feature 2 | Benefit 2
120
-
121
- ## 4.4 Assumptions and Dependencies
122
-
123
- List any assumptions that, if changed, will alter the vision for the product.
124
-
125
- ## 4.5 Cost and Pricing
126
-
127
- Describe any relevant cost and pricing constraints, because these can directly impact the solution definition and implementation.
128
-
129
- # 5 Product Features
130
-
131
- This section describes the intended product features. Features provide the system capabilities that are necessary to deliver benefits to the users. Feature descriptions should be short and pithy, a key phrase, perhaps followed by one or two sentences of explanation.
132
-
133
- Use a level of abstraction high enough to be able to describe the system with a maximum of 25 to 50 features. Each feature should be perceivable by users, operators, or other external systems.
134
-
135
- ## 5.1 Feature 1
136
-
137
- ## 5.2 Feature 2
138
-
139
- # 6 Exemplary Use Cases
140
-
141
- [Optional] You may want to describe a few exemplary use cases, perhaps those that are architecturally significant or those that will most readily help the reader understand how the system is intended to be used.
142
-
143
- # 7 Nonfunctional Requirements
144
-
145
- This section records other system requirements including nonfunctional requirements (constraints) imposed on the system (see Chapter 17).
146
-
147
- ## 7.1 Usability
148
-
149
- ## 7.2 Reliability
150
-
151
- ## 7.3 Performance
152
-
153
- ## 7.4 Supportability
154
-
155
- ## 7.5 Other Requirements
156
-
157
- ### 7.5.1 Applicable Standards
158
-
159
- List all standards the product must comply with, such as legal and regulatory, communications standards, platform compliance standards, and quality and safety standards.
160
-
161
- ### 7.5.2 System Requirements
162
-
163
- Define any system requirements necessary to support the application. These may include the host operating systems and network platforms, configurations, communication, peripherals, and companion software.
164
-
165
- ### 7.5.3 Licensing, Security, and Installation
166
-
167
- Licensing, security, and installation issues can also directly impact the development effort. Installation requirements may affect coding or create the need for separate installation software.
168
-
169
- # 8 Documentation Requirements
170
-
171
- This section describes the documentation that must be developed to support successful deployment and use.
172
-
173
- ## 8.1 User Manual
174
-
175
- Describe the intent of the user manual. Discuss desired length, level of detail, need for index and glossary, tutorial versus reference manual strategy, and so on. Formatting, electronic distribution, and printing constraints should also be identified.
176
-
177
- ## 8.2 Online Help
178
-
179
- The nature of these systems is unique to application development since they combine aspects of programming and hosting, such as hyperlinks and web services, with aspects of technical writing, such as organization, style, and presentation.
180
-
181
- ## 8.3 Installation Guides, Configuration, “Read Me” File
182
-
183
- A document that includes installation instructions and configuration guidelines is typically necessary. Also, a “read me” file is often included as a standard component. The “read me” file may include a “What’s New with This Release” section and a discussion of compatibility issues with earlier releases. Most users also appreciate publication of any known defects and workarounds.
184
-
185
- ## 8.4 Labeling and Packaging
186
-
187
- Defines the requirements for labeling to be incorporated into the code. Examples include copyright and patent notices, corporate logos, standardized icons, and other graphic elements.
188
-
189
- ## 9 Glossary
190
-
191
- The glossary defines terms that are unique to the program. Include any acronyms or abbreviations that need to be understood by users or other readers.
@@ -1,5 +0,0 @@
1
- module Marko
2
- Artifact = Struct.new(:title, :template, :filename)
3
- NULLFACT = Artifact.new("Artifact",
4
- "tt/default.md.tt", "bin/artifact.md") .freeze
5
- end
@@ -1,83 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "gadgets"
4
- require_relative "config"
5
- require_relative "loader"
6
- require_relative "tree_node"
7
-
8
- module Marko
9
-
10
- # The strategy for assembling sources into artifact tree
11
- class Assembler < Service
12
-
13
- class Failure # < StandardError
14
- attr_reader :errors
15
- def initialize(message, *errors)
16
- @errors = errors
17
- super(
18
- errors
19
- .map{|e| e.lines.map{|l| " #{l}"}.join }
20
- .unshift(message + ?\n)
21
- .join
22
- )
23
- end
24
- end
25
-
26
- # @return [TreeNode]
27
- def call
28
- @block.(:stage, 'loading sources') if @block
29
- buffer, errors = Loader.(&@block)
30
- fail Failure.new('markup parsing errors', *errors) if errors.any?
31
- @block.(:stage, 'tree assemblage') if @block
32
- # @todo fold first level when root note contain only one item?
33
- tree = assemble(buffer)
34
- @block.(:stage, 'tree enrichment') if @block
35
- injectid(tree)
36
- @block.(:stage, 'tree validation') if @block
37
- errors = validate(tree)
38
- fail Failure.new('tree validation errors', *errors) if errors.any?
39
- tree
40
- end
41
-
42
- protected
43
-
44
- # @param buff [Array<TreeNode>]
45
- # @return [TreeNode]
46
- def assemble(buff)
47
- art = Marko.artifact
48
- TreeNode.new(art.title, id: '0').tap {|root|
49
- # @todo buff.inject(root, :<<) wrong but why?
50
- buff.each{|n| root << n}
51
- root.items
52
- .select{|node| node[:parent] && node[:parent] != node.parent_id}
53
- .each{|node|
54
- parent = root.find{|n| n.id == node[:parent]}
55
- next unless parent # is must be left under root
56
- parent << node
57
- node.delete_meta(:parent)
58
- root.delete_item(node)
59
- }
60
- }
61
- end
62
-
63
- def injectid(tree)
64
- counter = {}
65
- tree
66
- .select {|node| node.id.empty?}
67
- .each do |node|
68
- index = counter[node.parent] || 1
69
- counter[node.parent] = index + 1
70
- id = index.to_s.rjust(2, '0')
71
- id = '.' + id unless node.parent == tree
72
- node[:id] = id
73
- end
74
- end
75
-
76
- def validate(tree)
77
- validator = ValidatorPlug.plugged
78
- validator.(tree)
79
- end
80
-
81
- end
82
-
83
- end
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "tree_node"
4
- require_relative "gadgets"
5
-
6
- module Marko
7
- class Compiler
8
- extend Pluggable
9
- def call(tree, template, filename, &block)
10
- @tree = MustbeTreeNode.(tree)
11
- @template = MustbeString.(template)
12
- @filename = MustbeString.(filename)
13
- @block = block
14
- end
15
- end
16
- end
@@ -1,55 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Marko
4
- # Pluggable mixin serves for dependency injection
5
- #
6
- # @example
7
- # class Storage
8
- # extend Pluggable
9
- # def call
10
- # end
11
- # end
12
- #
13
- # StoragePort = Storage.port
14
- #
15
- # class SequelStorage < Storage
16
- # end
17
- #
18
- # StoragePort.plugged = SequelStorage.new
19
- #
20
- # require 'forwardable'
21
- # class Service
22
- # extend Forwardable
23
- # def_delegator :StoragePort, :plugged, :storage
24
- # def call
25
- # storage.call
26
- # end
27
- # end
28
- module Pluggable
29
-
30
- def plug
31
- klass = self
32
- Module.new {
33
- extend Plug;
34
- plug klass
35
- }
36
- end
37
-
38
- module Plug
39
- def plug(klass)
40
- @klass = klass
41
- end
42
-
43
- def plugged
44
- fail "unknown @klass" unless @klass
45
- @plugged ||= @klass.new
46
- end
47
-
48
- def plugged=(obj)
49
- fail ArgumentError.new("required an instance of #{@klass}"
50
- ) unless obj.is_a?(@klass)
51
- @plugged = obj
52
- end
53
- end
54
- end
55
- end
@@ -1,66 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Marko
4
- # Factory module for guarding method arguments
5
- #
6
- # @example
7
- #
8
- # ShortString = Sentry.new(:str, "must be String[3..100]"
9
- # ) {|v| v.is_a?(String) && v.size.between?(3,100)}
10
- #
11
- # ShortString.(str) => "str"
12
- # ShortString.(nil) => ArgumentError ":str must be String[3..100]"
13
- # ShortString.error(nil) => ":str must be String[3..100]"
14
- # ShortString.error!(nil) => ArgumentError":str must be String[3..100]"
15
- # ShortString.(nil, :name) => ArgumentError ":name must be String[3..100]"
16
- # ShortString.(nil, 'John Doe', 'Ups!') => ArgumentError ":John Doe Ups!"
17
- #
18
- module Sentry
19
-
20
- # creates a new Sentry
21
- # @param key [Symbol|String] key for error message
22
- # @param msg [String] error message
23
- # @param blk [&block] validation block that should return boolen
24
- # @return [Sentry] based on key, msg, and validation block
25
- def self.new(key, msg, &blk)
26
- # origin ;)
27
- argerror = ->(val, msg, cnd) {
28
- fail ArgumentError, msg unless cnd
29
- val
30
- }
31
- Module.new do
32
- include Sentry
33
- extend self
34
-
35
- @key = argerror.(key, ":key must be Symbol|String",
36
- key.is_a?(String) || key.is_a?(Symbol))
37
- @msg = argerror.(msg, ":msg must be String", msg.is_a?(String))
38
- @blk = argerror.(blk, "&blk must be provided", block_given?)
39
- end
40
- end
41
-
42
- # returns error message for invalid :val
43
- # @param val [Object] value to be validated
44
- # @param key [Symbol|String] key for error message
45
- # @param msg [String] optional error message
46
- # @return [String] error message for invalid :val or nil when :val is valid
47
- def error(val, key = @key, msg = @msg)
48
- ":#{key} #{msg}" unless @blk.(val)
49
- end
50
-
51
- # guards :val
52
- # @todo @see Yard!
53
- # @param val [Object] value to be returned if it valid
54
- # @param key [Symbol|String] key for error message
55
- # @param msg [String] optional error message
56
- # @return [Object] valid :val or raieses ArgumentError when invalid
57
- def error!(val, key = @key, msg = @msg)
58
- return val if @blk.(val)
59
- fail ArgumentError, ":#{key} #{msg}", caller[0..-1]
60
- end
61
-
62
- # @todo how do describe in Yard?
63
- alias :call :error!
64
- end
65
-
66
- end
@@ -1,52 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Marko
4
- # Service like ServiceObject, Command, etc.
5
- #
6
- # @example just call without parameters
7
- # class BoldService < Service
8
- # def call
9
- # 42
10
- # end
11
- # end
12
- #
13
- # @example with parameters
14
- # class PlusService < Service
15
- # def initialize(a, b)
16
- # @a, @b = a, b
17
- # end
18
- #
19
- # def call
20
- # 42
21
- # end
22
- # end
23
- #
24
- class Service
25
- Failure = Class.new(StandardError)
26
-
27
- class << self
28
- def call(*args, **kwargs, &block)
29
- new(*args, **kwargs, &block).call
30
- end
31
-
32
- def inherited(klass)
33
- klass.const_set(:Failure, Class.new(klass::Failure))
34
- super
35
- end
36
- end
37
-
38
- private_class_method :new
39
-
40
- def initialize(*args, **kwargs, &block)
41
- @args = args
42
- @kwargs = kwargs
43
- @block = block
44
- end
45
-
46
- def call
47
- fail Failure, "#{self.class.name}#call must be overrided"
48
- end
49
-
50
- end
51
-
52
- end
data/lib/marko/gadgets.rb DELETED
@@ -1,3 +0,0 @@
1
- require_relative "gadgets/sentry"
2
- require_relative "gadgets/pluggable"
3
- require_relative "gadgets/service"
data/lib/marko/loader.rb DELETED
@@ -1,38 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "gadgets"
4
- require_relative "config"
5
-
6
- module Marko
7
-
8
- # The strategy class for loading sources from repository
9
- class Loader < Service
10
- # load markup sources, parse and return TreeNode buffer
11
- #
12
- # @example
13
- # fn = proc{|event, paylod| ... }
14
- # buffer, errors = loader.(&fn)
15
- # fail "Failed" if errors.any?
16
- # # procced ...
17
- #
18
- # @param block [&block] aka proc {|event, payload| ..}
19
- # @return [Array<TreeNode>, Array<String>] where
20
- # the first item is buffer and the second is array<error>
21
- def call
22
- buffer = []
23
- errors = []
24
- parser = ParserPlug.plugged
25
- storage = StoragePlug.plugged
26
- storage.sources.each do |source|
27
- @block.(:source, source) if @block
28
- content = storage.content(source)
29
- buff, errs = parser.(content, source, &@block)
30
- buffer.concat(buff)
31
- errors.concat(errs)
32
- @block.(:errors, errs) if @block
33
- end
34
- [buffer.flatten, errors]
35
- end
36
- end
37
-
38
- end
@@ -1,30 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "erb"
4
- require_relative "../compiler"
5
- require_relative "../config"
6
-
7
- module Marko
8
- module Markup
9
-
10
- class Compiler < Marko::Compiler
11
-
12
- # @see Marko::Compliler#call
13
- def call(tree, template, filename, &block)
14
- super(tree, template, filename, &block)
15
- compile
16
- end
17
-
18
- protected
19
-
20
- def compile
21
- storage = StoragePlug.plugged
22
- @model = @tree.map{|n| Markup::Decorator.new(n)}
23
- samplr = ERB.new(@template, trim_mode: '%<>')
24
- storage.write(@filename, samplr.result(binding))
25
- @filename
26
- end
27
- end
28
-
29
- end
30
- end
@@ -1,80 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "delegate"
4
-
5
- module Marko
6
- module Markup
7
-
8
- class Decorator < SimpleDelegator
9
-
10
- def initialize(obj)
11
- super(obj)
12
- @macroproc = MacroProcPlug.plugged
13
- end
14
-
15
- def title
16
- super.then{|s| s.empty? ? ".#{id.split(/\./).last}" : s}
17
- end
18
-
19
- def body
20
- @macroproc.process(super, self).strip
21
- end
22
-
23
- # @return [Hash] metdata cleaned from system meta
24
- def meta
25
- super.dup.tap{|h| h.update(id: id)}
26
- .reject{|k,_| %i[origin parent order_index].include?(k)}
27
- end
28
-
29
- def find_node(ref)
30
- obj = super(ref)
31
- return nil unless obj
32
- self.class.new(obj)
33
- end
34
-
35
- def ref
36
- "[#{title}](#{url})"
37
- end
38
-
39
- # @return [String] return header
40
- def topic
41
- return "% #{title}" if root?
42
- "#{'#' * nesting_level} #{title.strip} {#{url}}"
43
- end
44
- alias :header :topic
45
-
46
- # return [String] meta properties table
47
- def props
48
- meta.then{|h|
49
- klen = h.keys.map{ _1.to_s.size }.max + 4
50
- vlen = h.values.map(&:size).max
51
- mark = ?- * klen + ?\s + ?- * vlen
52
- h.map{|k, v| "__#{k.capitalize}__".ljust(klen) + ?\ + v }
53
- .unshift(mark)
54
- .push(mark)
55
- .join(?\n)
56
- }
57
- end
58
-
59
- # @return [String] decorated node content
60
- def text
61
- [ topic, props, body
62
- ].reject(&:empty?)
63
- .join("\n\n") +
64
- "\n\n"
65
- end
66
-
67
- protected
68
-
69
- def url
70
- id.downcase
71
- .gsub(/\W{1,}/, '-')
72
- .gsub(/^-/, '')
73
- .gsub(/-$/, '')
74
- .then{"##{_1}"}
75
- end
76
-
77
- end
78
-
79
- end
80
- end