saga 0.9.0 → 0.9.1
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.
- data/lib/saga/parser.rb +14 -6
- data/lib/saga/tokenizer.rb +14 -4
- metadata +5 -5
data/lib/saga/parser.rb
CHANGED
@@ -5,10 +5,15 @@ module Saga
|
|
5
5
|
def initialize
|
6
6
|
@tokenizer = ::Saga::Tokenizer.new(self)
|
7
7
|
@document = ::Saga::Document.new
|
8
|
-
|
8
|
+
self.current_section = :title
|
9
9
|
@current_header = ''
|
10
10
|
end
|
11
11
|
|
12
|
+
def current_section=(section)
|
13
|
+
@current_section = section
|
14
|
+
@tokenizer.current_section = section
|
15
|
+
end
|
16
|
+
|
12
17
|
def parse(input)
|
13
18
|
@tokenizer.process(input)
|
14
19
|
@document
|
@@ -19,13 +24,13 @@ module Saga
|
|
19
24
|
end
|
20
25
|
|
21
26
|
def handle_story(story)
|
22
|
-
|
27
|
+
self.current_section = :stories
|
23
28
|
@document.stories[@current_header] ||= []
|
24
29
|
@document.stories[@current_header] << story
|
25
30
|
end
|
26
31
|
|
27
32
|
def handle_nested_story(story)
|
28
|
-
|
33
|
+
self.current_section = :story
|
29
34
|
parent = @document.stories[@current_header][-1]
|
30
35
|
parent[:stories] ||= []
|
31
36
|
parent[:stories] << story
|
@@ -41,18 +46,21 @@ module Saga
|
|
41
46
|
end
|
42
47
|
|
43
48
|
def handle_definition(definition)
|
44
|
-
|
49
|
+
self.current_section = :definitions
|
45
50
|
@document.definitions[@current_header] ||= []
|
46
51
|
@document.definitions[@current_header] << definition
|
47
52
|
end
|
48
53
|
|
49
54
|
def handle_string(string)
|
50
55
|
return if string.strip == ''
|
51
|
-
|
56
|
+
if string.strip == 'USER STORIES'
|
57
|
+
self.current_section = :stories
|
58
|
+
return @current_section
|
59
|
+
end
|
52
60
|
|
53
61
|
if :title == @current_section
|
54
62
|
@document.title = string.gsub(/^requirements/i, '').strip
|
55
|
-
|
63
|
+
self.current_section = :introduction
|
56
64
|
elsif :introduction == @current_section
|
57
65
|
@document.introduction << string
|
58
66
|
else
|
data/lib/saga/tokenizer.rb
CHANGED
@@ -1,13 +1,21 @@
|
|
1
1
|
module Saga
|
2
2
|
class Tokenizer
|
3
|
+
attr_accessor :current_section
|
4
|
+
|
5
|
+
RE_STORY = /\./
|
6
|
+
RE_DEFINITION = /\A\w(\w|[\s-])+:/
|
7
|
+
|
3
8
|
def initialize(parser)
|
4
9
|
@parser = parser
|
10
|
+
@part = :current_section
|
11
|
+
end
|
12
|
+
|
13
|
+
def expect_stories?
|
14
|
+
%w(story stories).include?(@current_section.to_s)
|
5
15
|
end
|
6
16
|
|
7
17
|
def process_line(input)
|
8
|
-
if input[0,2]
|
9
|
-
@parser.handle_story(self.class.tokenize_story(input))
|
10
|
-
elsif input[0,2] == ' '
|
18
|
+
if input[0,2] == ' '
|
11
19
|
@parser.handle_notes(input.strip)
|
12
20
|
elsif input[0,3] == '| '
|
13
21
|
@parser.handle_notes(input[1..-1].strip)
|
@@ -15,8 +23,10 @@ module Saga
|
|
15
23
|
@parser.handle_nested_story(self.class.tokenize_story(input[1..-1]))
|
16
24
|
elsif input[0,1] == '-'
|
17
25
|
@parser.handle_author(self.class.tokenize_author(input))
|
18
|
-
elsif input =~
|
26
|
+
elsif input =~ RE_DEFINITION
|
19
27
|
@parser.handle_definition(self.class.tokenize_definition(input))
|
28
|
+
elsif expect_stories? && input =~ RE_STORY
|
29
|
+
@parser.handle_story(self.class.tokenize_story(input))
|
20
30
|
else
|
21
31
|
@parser.handle_string(input)
|
22
32
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: saga
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 57
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 9
|
9
|
-
-
|
10
|
-
version: 0.9.
|
9
|
+
- 1
|
10
|
+
version: 0.9.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Manfred Stienstra
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-07-
|
18
|
+
date: 2012-07-19 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: erubis
|
@@ -76,7 +76,7 @@ dependencies:
|
|
76
76
|
type: :development
|
77
77
|
version_requirements: *id004
|
78
78
|
description: Saga is a tool to convert stories syntax to a nicely formatted document.
|
79
|
-
email: manfred@
|
79
|
+
email: manfred@fngtps.com
|
80
80
|
executables:
|
81
81
|
- saga
|
82
82
|
extensions: []
|