brief 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +70 -0
  3. data/Gemfile.lock +2 -2
  4. data/README.md +143 -70
  5. data/lib/brief/adapters/middleman.rb +2 -3
  6. data/lib/brief/briefcase.rb +28 -5
  7. data/lib/brief/cli/change.rb +7 -7
  8. data/lib/brief/cli/init.rb +10 -11
  9. data/lib/brief/cli/write.rb +23 -0
  10. data/lib/brief/configuration.rb +3 -4
  11. data/lib/brief/document/content_extractor.rb +2 -4
  12. data/lib/brief/document/front_matter.rb +4 -4
  13. data/lib/brief/document/rendering.rb +7 -9
  14. data/lib/brief/document/section/builder.rb +10 -10
  15. data/lib/brief/document/section/mapping.rb +5 -11
  16. data/lib/brief/document/section.rb +2 -3
  17. data/lib/brief/document/structure.rb +14 -15
  18. data/lib/brief/document/templating.rb +14 -0
  19. data/lib/brief/document.rb +20 -9
  20. data/lib/brief/document_mapper.rb +10 -10
  21. data/lib/brief/dsl.rb +5 -6
  22. data/lib/brief/model/definition.rb +37 -13
  23. data/lib/brief/model/persistence.rb +0 -2
  24. data/lib/brief/model.rb +50 -21
  25. data/lib/brief/repository.rb +2 -3
  26. data/lib/brief/util.rb +4 -4
  27. data/lib/brief/version.rb +1 -1
  28. data/lib/brief.rb +47 -33
  29. data/spec/fixtures/example/brief.rb +3 -0
  30. data/spec/fixtures/example/models/epic.rb +43 -5
  31. data/spec/fixtures/example/templates/user_story.md.erb +22 -0
  32. data/spec/lib/brief/briefcase_spec.rb +1 -1
  33. data/spec/lib/brief/dsl_spec.rb +1 -1
  34. data/spec/lib/brief/model_spec.rb +6 -1
  35. data/spec/lib/brief/persistence_spec.rb +1 -1
  36. data/spec/lib/brief/repository_spec.rb +1 -1
  37. data/spec/lib/brief/template_spec.rb +44 -0
  38. data/spec/spec_helper.rb +2 -2
  39. metadata +7 -2
data/lib/brief/util.rb CHANGED
@@ -7,19 +7,19 @@ module Brief::Util
7
7
  c.syntax = "brief #{identifier}"
8
8
  c.description = "run the #{identifier} command"
9
9
 
10
- c.action do |args, opts|
10
+ c.action do |args, _opts|
11
11
  briefcase = Brief.case
12
12
 
13
- path_args = args.select {|arg| arg.is_a?(String) && arg.match(/\.md$/) }
13
+ path_args = args.select { |arg| arg.is_a?(String) && arg.match(/\.md$/) }
14
14
 
15
15
  path_args.select! do |arg|
16
16
  path = briefcase.repository.root.join(arg)
17
17
  path.exist?
18
18
  end
19
19
 
20
- path_args.map! {|p| briefcase.repository.root.join(p) }
20
+ path_args.map! { |p| briefcase.repository.root.join(p) }
21
21
 
22
- models = path_args.map {|path| Brief::Document.new(path) }.map(&:to_model)
22
+ models = path_args.map { |path| Brief::Document.new(path) }.map(&:to_model)
23
23
 
24
24
  if models.empty?
25
25
  model_finder = c.name.to_s.split(' ').last
data/lib/brief/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Brief
2
- VERSION = "1.2.0"
2
+ VERSION = '1.3.0'
3
3
  end
data/lib/brief.rb CHANGED
@@ -1,16 +1,17 @@
1
- require "pathname"
2
- require "set"
3
- require "hashie"
4
- require "virtus"
5
- require "inflecto"
6
- require "active_support"
7
- require "active_support/core_ext"
8
- require "redcarpet"
9
- require "nokogiri"
10
- require "yaml"
1
+ require 'pathname'
2
+ require 'set'
3
+ require 'hashie'
4
+ require 'virtus'
5
+ require 'inflecto'
6
+ require 'active_support'
7
+ require 'active_support/core_ext'
8
+ require 'redcarpet'
9
+ require 'nokogiri'
10
+ require 'yaml'
11
+ require 'erb'
11
12
 
12
13
  module Brief
13
- def self.case= value
14
+ def self.case=(value)
14
15
  @briefcase = value
15
16
  end
16
17
 
@@ -26,8 +27,12 @@ module Brief
26
27
  Pathname(File.dirname(__FILE__))
27
28
  end
28
29
 
30
+ def self.apps_path
31
+ gem_root.join("..","apps")
32
+ end
33
+
29
34
  def self.load_commands
30
- Dir[gem_root.join("brief","cli","**/*.rb")].each {|f| require(f) }
35
+ Dir[gem_root.join('brief', 'cli', '**/*.rb')].each { |f| require(f) }
31
36
 
32
37
  # the instance methods which get defined with the helper
33
38
  Brief::Model.classes.each do |klass|
@@ -37,8 +42,16 @@ module Brief
37
42
  end
38
43
  end
39
44
 
40
- def self.load_models(from_folder=nil)
41
- Brief::Model.load_all(from_folder: from_folder)
45
+ def self.default_model_class
46
+ if defined?(Brief::DefaultModel)
47
+ Brief::DefaultModel
48
+ else
49
+ Brief.const_set(:DefaultModel, Class.new { include Brief::Model; def self.type_alias; "default"; end })
50
+ end
51
+ end
52
+
53
+ def self.load_modules_from(folder)
54
+ Dir[folder.join('**/*.rb')].each { |f| require(f) }
42
55
  end
43
56
 
44
57
  # Adapters for Rails, Middleman, or Jekyll apps
@@ -49,22 +62,23 @@ module Brief
49
62
  end
50
63
  end
51
64
 
52
- require "brief/core_ext"
53
- require "brief/version"
54
- require "brief/util"
55
- require "brief/configuration"
56
- require "brief/document/rendering"
57
- require "brief/document/front_matter"
58
- require "brief/document/content_extractor"
59
- require "brief/document/structure"
60
- require "brief/document/section"
61
- require "brief/document/section/mapping"
62
- require "brief/document/section/builder"
63
- require "brief/document"
64
- require "brief/document_mapper"
65
- require "brief/repository"
66
- require "brief/model"
67
- require "brief/model/definition"
68
- require "brief/model/persistence"
69
- require "brief/dsl"
70
- require "brief/briefcase"
65
+ require 'brief/core_ext'
66
+ require 'brief/version'
67
+ require 'brief/util'
68
+ require 'brief/configuration'
69
+ require 'brief/document/rendering'
70
+ require 'brief/document/front_matter'
71
+ require 'brief/document/templating'
72
+ require 'brief/document/content_extractor'
73
+ require 'brief/document/structure'
74
+ require 'brief/document/section'
75
+ require 'brief/document/section/mapping'
76
+ require 'brief/document/section/builder'
77
+ require 'brief/document'
78
+ require 'brief/document_mapper'
79
+ require 'brief/repository'
80
+ require 'brief/model'
81
+ require 'brief/model/definition'
82
+ require 'brief/model/persistence'
83
+ require 'brief/dsl'
84
+ require 'brief/briefcase'
@@ -1,5 +1,6 @@
1
1
  config do
2
2
  set(:models => Pathname(File.dirname(__FILE__)).join("models"))
3
+ set(:templates => Pathname(File.dirname(__FILE__)).join("templates"))
3
4
  end
4
5
 
5
6
  define "User Story" do
@@ -9,6 +10,8 @@ define "User Story" do
9
10
  epic_title
10
11
  end
11
12
 
13
+ template :file => "user_story.md.erb"
14
+
12
15
  content do
13
16
  persona "p strong:first-child"
14
17
  behavior "p strong:second-child"
@@ -7,22 +7,60 @@ class Brief::Epic
7
7
  status String, :in => %w(draft published)
8
8
  end
9
9
 
10
+ example <<-EOF
11
+ ---
12
+ type: epic
13
+ status: draft
14
+ ---
15
+
16
+ # Epic Title
17
+
18
+ Write a description for your epic.
19
+
20
+ # User Stories
21
+
22
+ ## User Story Title
23
+
24
+ As a **PERSONA** I would like to **BEHAVIOR** so that I can **GOAL**
25
+ EOF
26
+
27
+ template <<-EOF
28
+ # <%= object.title %>
29
+ # User Stories
30
+ <% Array(object.user_stories).each do |user_story| %>
31
+ ## <%= user_story.title %>
32
+ As a **User** I would like to **Do this** so that I can **succeed**
33
+ <% end %>
34
+ EOF
35
+
10
36
  content do
11
- # have to do this so that the user stories section h1 doesnt get confused
12
37
  title "h1:first-of-type"
13
-
14
38
  define_section "User Stories" do
15
- # NOT YET Implemented
16
- each("h2").is_a :user_story
17
-
18
39
  each("h2").has(:title => "h2",
19
40
  :paragraph => "p:first-of-type",
20
41
  :components => "p:first-of-type strong"
21
42
  )
43
+
44
+ each("h2").is_a :user_story
45
+ end
46
+ end
47
+
48
+ helpers do
49
+ def user_stories
50
+ sections.user_stories.items.map do |item|
51
+ item.components = Array(item.components)
52
+
53
+ item.merge(goal: item.components[2],
54
+ persona: item.components[0],
55
+ behavior: item.components[1])
56
+ end
22
57
  end
23
58
  end
24
59
 
25
60
  actions do
61
+ def publish_to_github
62
+ end
63
+
26
64
  def custom_action
27
65
  end
28
66
  end
@@ -0,0 +1,22 @@
1
+ # <%= object.title %>
2
+
3
+ <% if object.persona && object.behavior %>
4
+ As a **<%= object.persona %>** I would like to <%= object.behavior %>** <% if object.goal; %> so that I can **<%= object.goal %>** <% end; %>
5
+ <% elsif object.paragraph.to_s.length > 0 %>
6
+ <%= object.paragraph %>
7
+ <% end %>
8
+
9
+ <% if object.wireframes %>
10
+ ### Wireframes
11
+ <% Array(object.wireframes).each do |wireframe| %>
12
+ - <%= wireframe %>
13
+ <% end %>
14
+ <% end %>
15
+
16
+ <% if object.estimates %>
17
+ ### Estimates
18
+ <% Array(object.estimates).each do |estimate| %>
19
+ - <%= estimate %>
20
+ <% end %>
21
+ <% end %>
22
+
@@ -1,7 +1,7 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe "The Briefcase" do
4
- let(:briefcase) { Brief.example }
4
+ let(:briefcase) { Brief.testcase }
5
5
 
6
6
  it "has a root path" do
7
7
  expect(briefcase.root).to be_exist
@@ -2,7 +2,7 @@ require "spec_helper"
2
2
 
3
3
 
4
4
  describe "The Configuration DSL" do
5
- let(:briefcase) { Brief.example }
5
+ let(:briefcase) { Brief.testcase }
6
6
 
7
7
  it "can create methods on our models" do
8
8
  expect(briefcase.user_stories.first.defined_helper_method).to eq(true)
@@ -1,7 +1,7 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe "The Brief Model" do
4
- let(:briefcase) { Brief.example }
4
+ let(:briefcase) { Brief.testcase }
5
5
  let(:epic) { briefcase.epics.first }
6
6
  let(:user_story) { briefcase.user_stories.first }
7
7
 
@@ -101,6 +101,11 @@ describe "The Brief Model" do
101
101
  it "users the actions block to define CLI dispatchers (dsl)" do
102
102
  expect(user_story.class.defined_actions).to include(:custom_action)
103
103
  end
104
+
105
+ it "lets me define a helper method which utilizes all the extracted data and content structure" do
106
+ expect(epic.user_stories.length).to eq(3)
107
+ expect(epic.user_stories.map(&:persona)).to include("User")
108
+ end
104
109
  end
105
110
 
106
111
  context "Section Mappings" do
@@ -1,7 +1,7 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe "Updating Model Data" do
4
- let(:briefcase) { Brief.example }
4
+ let(:briefcase) { Brief.testcase }
5
5
 
6
6
  it "lets me set new attributes on the model" do
7
7
  end
@@ -1,7 +1,7 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe "The Brief Document Repository" do
4
- let(:repository) { Brief.example.repository }
4
+ let(:repository) { Brief.testcase.repository }
5
5
 
6
6
  it "has a bunch of documents" do
7
7
  expect(repository.documents).not_to be_empty
@@ -0,0 +1,44 @@
1
+ require "spec_helper"
2
+
3
+ describe "Document Templates" do
4
+ let(:data) do
5
+ {
6
+ title: "Epic Example",
7
+ status: "published",
8
+ type: "epic",
9
+ user_stories:[{
10
+ title: "A user wants to do something",
11
+ paragraph: "As a user I would like to do something so that I can succeed",
12
+ goal: "I can succeed",
13
+ persona: "user",
14
+ behavior: "do something"
15
+ },{
16
+ title: "A user wants to do something else",
17
+ paragraph: "As a user I would like to do something else so that I can succeed"
18
+ }]
19
+ }
20
+ end
21
+
22
+ it "has template body" do
23
+ expect(Brief::Epic.template_body).not_to be_empty
24
+ end
25
+
26
+ it "has an example" do
27
+ expect(Brief::Epic.example_body).not_to be_empty
28
+ end
29
+
30
+ it "takes a hash of data and renders yaml frontmatter" do
31
+ expect(Brief::Document.create_from_data(data).title).to eq("Epic Example")
32
+ end
33
+
34
+ it "supports more complex renderings" do
35
+ doc = Brief::Document.create_from_data(data)
36
+ content = doc.content
37
+
38
+ expect(content).to include("# User Stories")
39
+ expect(content).to include("# Epic Example")
40
+ expect(content).to include("## A user wants to do something")
41
+ expect(content).to include("## A user wants to do something else")
42
+ end
43
+
44
+ end
data/spec/spec_helper.rb CHANGED
@@ -9,10 +9,10 @@ module Brief
9
9
  end
10
10
 
11
11
  def self.example_path
12
- example.root
12
+ testcase.root
13
13
  end
14
14
 
15
- def self.example
15
+ def self.testcase
16
16
  @example ||= Brief::Briefcase.new(root:spec_root.join("fixtures","example"))
17
17
  end
18
18
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brief
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Soeder
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-23 00:00:00.000000000 Z
11
+ date: 2015-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashie
@@ -244,6 +244,7 @@ files:
244
244
  - lib/brief/document/section/builder.rb
245
245
  - lib/brief/document/section/mapping.rb
246
246
  - lib/brief/document/structure.rb
247
+ - lib/brief/document/templating.rb
247
248
  - lib/brief/document_mapper.rb
248
249
  - lib/brief/dsl.rb
249
250
  - lib/brief/model.rb
@@ -261,6 +262,7 @@ files:
261
262
  - spec/fixtures/example/docs/user_story.html.md
262
263
  - spec/fixtures/example/docs/wireframe.html.md
263
264
  - spec/fixtures/example/models/epic.rb
265
+ - spec/fixtures/example/templates/user_story.md.erb
264
266
  - spec/fixtures/structures/one.html.md
265
267
  - spec/fixtures/structures/three.html.md
266
268
  - spec/fixtures/structures/two.html.md
@@ -273,6 +275,7 @@ files:
273
275
  - spec/lib/brief/repository_spec.rb
274
276
  - spec/lib/brief/section_builder_spec.rb
275
277
  - spec/lib/brief/structure_spec.rb
278
+ - spec/lib/brief/template_spec.rb
276
279
  - spec/spec_helper.rb
277
280
  - spec/support/test_helpers.rb
278
281
  - tasks/brief/release.rake
@@ -310,6 +313,7 @@ test_files:
310
313
  - spec/fixtures/example/docs/user_story.html.md
311
314
  - spec/fixtures/example/docs/wireframe.html.md
312
315
  - spec/fixtures/example/models/epic.rb
316
+ - spec/fixtures/example/templates/user_story.md.erb
313
317
  - spec/fixtures/structures/one.html.md
314
318
  - spec/fixtures/structures/three.html.md
315
319
  - spec/fixtures/structures/two.html.md
@@ -322,6 +326,7 @@ test_files:
322
326
  - spec/lib/brief/repository_spec.rb
323
327
  - spec/lib/brief/section_builder_spec.rb
324
328
  - spec/lib/brief/structure_spec.rb
329
+ - spec/lib/brief/template_spec.rb
325
330
  - spec/spec_helper.rb
326
331
  - spec/support/test_helpers.rb
327
332
  has_rdoc: