brief 1.7.2 → 1.7.3

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1274b95c43a49d1b2090319bd2835032a85379fe
4
- data.tar.gz: 602de90a32e517581da9a6fc10b6d146de3cd751
3
+ metadata.gz: 9a3acf77feeaf14fa2cd960e182ef9d3983272bb
4
+ data.tar.gz: a49c26a0ab788f553faef5e06c2ee4c78935fad8
5
5
  SHA512:
6
- metadata.gz: 4ba19577490cbf2f2fcab6bb7398d58db0335a1bb700877778a41be3bf2fd75eb4a4b68f6081587ba4e1a917d801a95da454b2c81e56c6baad3a62ccf255fbad
7
- data.tar.gz: 0d378928c0c0c1d1dd634b6089c64a81ff7a77104df846c1fc8dca486587afb2febae85e53e5bbed95d0ba652a47a7e94bb796f5d2fc60f593979ea8e1d5e913
6
+ metadata.gz: d8d95128ea80a9a7b03c49eb1d12cccfdc1792468e2fc713e74d34ff342086a3748d66243969deae46df73876da2d99284ab32e46001a6c6ac23c830fb48747d
7
+ data.tar.gz: abfdd1bc9606144883135179ecf6b28316caf9b886c9d33b60eb41057fb4e0a953748ec2c5b7d02fd92ebcd8c937739c9b72e24cd44374bbedf2d047b7e76275
data/.gitignore CHANGED
@@ -1,3 +1,4 @@
1
1
  # the test suite writes to this
2
2
  spec/fixtures/example/docs
3
3
  spec/fixtures/example/docs
4
+ tests/middleman/build
@@ -1,9 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- brief (1.7.1)
4
+ brief (1.7.2)
5
5
  activemodel
6
- activesupport
6
+ activesupport (>= 4.0)
7
7
  commander (>= 4.2.1)
8
8
  github-fs
9
9
  hashie
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.add_dependency 'virtus', '>= 1.0.3'
25
25
  spec.add_dependency 'inflecto'
26
26
  spec.add_dependency 'activemodel'
27
- spec.add_dependency 'activesupport'
27
+ spec.add_dependency 'activesupport', '>= 4.0'
28
28
  spec.add_dependency 'redcarpet', '>= 3.2.2'
29
29
  spec.add_dependency 'nokogiri'
30
30
 
@@ -69,8 +69,9 @@ module Brief
69
69
  # Adapters for Rails, Middleman, or Jekyll apps
70
70
  def self.activate_adapter(identifier)
71
71
  require "brief/adapters/#{ identifier }"
72
- adapter = (Brief::Adapters.const_get(identifier.camelize) rescue nil)
73
- adapter.try(:activate_adapter)
72
+ (Brief::Adapters.const_get(identifier.camelize) rescue nil).tap do |adapter|
73
+ raise "Invalid adapter: #{ identifier }" unless adapter
74
+ end
74
75
  end
75
76
  end
76
77
 
@@ -99,3 +100,4 @@ require 'brief/briefcase'
99
100
  require 'brief/apps'
100
101
 
101
102
  Brief::Apps.create_namespaces()
103
+ Brief.activate_adapter("middleman_extension").activate_brief_extension() if defined?(::Middleman)
@@ -0,0 +1,41 @@
1
+ module Brief::Adapters
2
+ class MiddlemanExtension < ::Middleman::Extension
3
+ def self.activate_brief_extension
4
+ ::Middleman::Extensions.register(:brief, Brief::Adapters::MiddlemanExtension)
5
+ end
6
+
7
+ def initialize(app, options_hash = {}, &block)
8
+ super
9
+
10
+ end
11
+
12
+ helpers do
13
+ def brief_config_path
14
+ Pathname(root).join("brief.rb")
15
+ end
16
+
17
+ def briefs
18
+ briefcase
19
+ end
20
+
21
+ def briefcase
22
+ if !brief_config_path.exist?
23
+ brief_config_path.open("w+") {|fh| fh.write("# See github.com/datapimp/brief for documentation")}
24
+ end
25
+
26
+ if development?
27
+ Brief::Briefcase.new(root: root,
28
+ config_path: brief_config_path,
29
+ caching: false)
30
+ else
31
+ @briefs ||= begin
32
+ Brief::Briefcase.new(root: root,
33
+ config_path: brief_config_path,
34
+ caching: true)
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ end
41
+ end
@@ -80,8 +80,10 @@ module Brief
80
80
  end
81
81
  end
82
82
 
83
- def config
84
- Brief::Configuration.instance
83
+ def config(&block)
84
+ Brief::Configuration.instance.tap do |cfg|
85
+ cfg.instance_eval(&block) if block.respond_to?(:call)
86
+ end
85
87
  end
86
88
 
87
89
  def server(options={})
@@ -106,6 +106,11 @@ module Brief
106
106
 
107
107
  def in_briefcase(briefcase)
108
108
  @briefcase_root = briefcase.root
109
+
110
+ unless Brief::Util.ensure_child_path(briefcase.docs_path, path)
111
+ raise 'Invalid document path'
112
+ end
113
+
109
114
  self
110
115
  end
111
116
 
@@ -154,7 +154,7 @@ module Brief
154
154
  end
155
155
 
156
156
  def level(element)
157
- element.name.to_s.gsub(/^h/i, '').to_i
157
+ (element && element.name.to_s.gsub(/^h/i, '')).to_i
158
158
  end
159
159
  end
160
160
  end
@@ -23,6 +23,11 @@ module Brief
23
23
  def method_missing(meth, *args, &block)
24
24
  in_model_group = model_groups.include?(meth.to_s)
25
25
 
26
+ if options[:caching] == false || options[:cache] == false
27
+ @all_models = nil
28
+ @all_models_by_type = nil
29
+ end
30
+
26
31
  if in_model_group && args.empty?
27
32
  find_models_by_type(meth)
28
33
  elsif in_model_group && !args.empty?
@@ -52,8 +57,14 @@ module Brief
52
57
  documents_at(*paths).select {|doc| doc.path.exist? }
53
58
  end
54
59
 
60
+ InvalidPath = Class.new(Exception)
61
+
55
62
  def normalize_path(p)
56
- docs_path.join(p)
63
+ docs_path.join(p).tap do |normalized|
64
+ if normalized.to_s.split("/").length < docs_path.realpath.to_s.split("/").length
65
+ raise InvalidPath
66
+ end
67
+ end
57
68
  end
58
69
 
59
70
  def documents_at(*paths)
@@ -96,7 +107,7 @@ module Brief
96
107
  end
97
108
 
98
109
  def document_paths
99
- Dir[root.join('**/*.md').to_s].map { |p| Pathname(p) }
110
+ Dir[docs_path.join('**/*.md').to_s].map { |p| Pathname(p) }
100
111
  end
101
112
 
102
113
  def all_models
@@ -1,8 +1,18 @@
1
1
  module Brief::Server::Handlers
2
2
  class Browse
3
+ def self.available_handlers
4
+ Brief::Model.classes.map(&:type_alias).map(&:pluralize)
5
+ end
6
+
3
7
  def self.handle(path_args, briefcase, options={})
4
- models = Array((briefcase.send(path_args) rescue nil))
5
- [200, {"Content-Type"=>"application/json"}, models.map(&:as_json)]
8
+ model_type = Array(path_args).first
9
+
10
+ if available_handlers.include?(model_type)
11
+ models = briefcase.send(model_type.to_s)
12
+ [200, {"Content-Type"=>"application/json"}, models.map(&:as_json)]
13
+ else
14
+ [403, {"Content-Type"=>"application/json"}, {error: "Invalid model type"}]
15
+ end
6
16
  end
7
17
  end
8
18
  end
@@ -56,6 +56,11 @@ module Brief::Server::Handlers
56
56
  return @errors
57
57
  end
58
58
 
59
+ if !Brief::Util.ensure_child_path(briefcase.docs_path, path)
60
+ @errors[:path] = "Invalid Path"
61
+ return @errors
62
+ end
63
+
59
64
  doc = Brief::Document.new(path).tap do |document|
60
65
  document.in_briefcase(briefcase)
61
66
 
@@ -7,7 +7,11 @@ module Brief::Server::Handlers
7
7
  view = parts.shift.to_s.downcase
8
8
  path = parts.join("/")
9
9
 
10
- document = briefcase.document_at(path) rescue nil
10
+ document = begin
11
+ briefcase.document_at(path)
12
+ rescue Brief::Repository::InvalidPath
13
+ :forbidden
14
+ end
11
15
 
12
16
  code = 200
13
17
  content_type = "application/json"
@@ -16,6 +20,9 @@ module Brief::Server::Handlers
16
20
  when document.nil?
17
21
  code = 404
18
22
  body = {error: "Not found"}
23
+ when document == :forbidden
24
+ code = 403
25
+ body = {error: "Access denied." }
19
26
  when !%w(content rendered details).include?(view)
20
27
  code = 400
21
28
  body = {error: "Invalid view: must be content, rendered, details" }
@@ -1,4 +1,17 @@
1
1
  module Brief::Util
2
+ def self.ensure_child_path(root, testpath)
3
+ root = Pathname(root).realpath.to_s.downcase
4
+ testpath = Pathname(testpath).parent.realpath.to_s.downcase
5
+
6
+ outside = !!(root.split("/").length > testpath.split("/").length)
7
+
8
+ if !outside && testpath.match(/^#{root}/)
9
+ return true
10
+ end
11
+
12
+ false
13
+ end
14
+
2
15
  def self.split_doc_content(raw_content)
3
16
  if raw_content =~ /^(---\s*\n.*?\n?)^(---\s*$\n?)/m
4
17
  content = raw_content[(Regexp.last_match[1].size + Regexp.last_match[2].size)..-1]
@@ -1,3 +1,3 @@
1
1
  module Brief
2
- VERSION = '1.7.2'
2
+ VERSION = '1.7.3'
3
3
  end
@@ -1,6 +1,11 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe "Modifying Documents", :type => :request do
4
+ it "will not let me work with a document outside of the root" do
5
+ post "/create/epics/../../../newly-created-epic.html.md", content: "# Epic Title"
6
+ expect(last_response.status).to eq(500)
7
+ end
8
+
4
9
  it "lets me create new documents by passing data and content" do
5
10
  begin
6
11
  post "/create/epics/newly-created-epic.html.md", content: "# Epic Title"
@@ -1,6 +1,12 @@
1
1
  require "spec_helper"
2
2
 
3
3
  describe "Viewing a Briefcase Document", :type => :request do
4
+
5
+ it "does not show the document content if it is invalid" do
6
+ get("/view/content/../../../../spec_helper.rb")
7
+ expect(last_response.status).to eq(403)
8
+ end
9
+
4
10
  it "shows the document content" do
5
11
  get("/view/content/epics/epic.html.md")
6
12
  expect(last_response.status).to eq(200)
@@ -5,6 +5,9 @@ describe "The Brief Document" do
5
5
  Brief.example_document
6
6
  end
7
7
 
8
+ it "wont let me create a document outside of the briefcase" do
9
+ expect(lambda { Brief::Document.new("/test.html.md").in_briefcase(Brief.testcase) }).to raise_error
10
+ end
8
11
  it "creates a new doc if the path doesn't exist" do
9
12
  begin
10
13
  new_path = Brief.testcase.docs_path.join("newly-created.html.md")
@@ -4,6 +4,6 @@ describe "Simple Files" do
4
4
  let(:doc) { Brief.testcase.releases.first }
5
5
 
6
6
  it "still renders simple html with no headings" do
7
- binding.pry
7
+ expect(lambda { doc.to_html }).not_to raise_error
8
8
  end
9
9
  end
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'middleman', '~> 3.3.9'
4
+ gem "pry"
5
+ gem "brief", :path => File.join(File.dirname(__FILE__), "..","..")
@@ -0,0 +1,178 @@
1
+ PATH
2
+ remote: /Users/jonathan/Gems/brief
3
+ specs:
4
+ brief (1.7.2)
5
+ activemodel
6
+ activesupport (>= 4.0)
7
+ commander (>= 4.2.1)
8
+ github-fs
9
+ hashie
10
+ inflecto
11
+ nokogiri
12
+ redcarpet (>= 3.2.2)
13
+ virtus (>= 1.0.3)
14
+
15
+ GEM
16
+ remote: https://rubygems.org/
17
+ specs:
18
+ activemodel (4.1.9)
19
+ activesupport (= 4.1.9)
20
+ builder (~> 3.1)
21
+ activesupport (4.1.9)
22
+ i18n (~> 0.6, >= 0.6.9)
23
+ json (~> 1.7, >= 1.7.7)
24
+ minitest (~> 5.1)
25
+ thread_safe (~> 0.1)
26
+ tzinfo (~> 1.1)
27
+ addressable (2.3.7)
28
+ axiom-types (0.1.1)
29
+ descendants_tracker (~> 0.0.4)
30
+ ice_nine (~> 0.11.0)
31
+ thread_safe (~> 0.3, >= 0.3.1)
32
+ builder (3.2.2)
33
+ celluloid (0.16.0)
34
+ timers (~> 4.0.0)
35
+ chunky_png (1.3.4)
36
+ coderay (1.1.0)
37
+ coercible (1.0.0)
38
+ descendants_tracker (~> 0.0.1)
39
+ coffee-script (2.3.0)
40
+ coffee-script-source
41
+ execjs
42
+ coffee-script-source (1.9.1)
43
+ commander (4.3.0)
44
+ highline (~> 1.6.11)
45
+ compass (1.0.3)
46
+ chunky_png (~> 1.2)
47
+ compass-core (~> 1.0.2)
48
+ compass-import-once (~> 1.0.5)
49
+ rb-fsevent (>= 0.9.3)
50
+ rb-inotify (>= 0.9)
51
+ sass (>= 3.3.13, < 3.5)
52
+ compass-core (1.0.3)
53
+ multi_json (~> 1.0)
54
+ sass (>= 3.3.0, < 3.5)
55
+ compass-import-once (1.0.5)
56
+ sass (>= 3.2, < 3.5)
57
+ descendants_tracker (0.0.4)
58
+ thread_safe (~> 0.3, >= 0.3.1)
59
+ equalizer (0.0.9)
60
+ erubis (2.7.0)
61
+ execjs (2.4.0)
62
+ faraday (0.9.1)
63
+ multipart-post (>= 1.2, < 3)
64
+ ffi (1.9.6)
65
+ github-fs (0.0.1)
66
+ activesupport (> 3.2.0)
67
+ octokit
68
+ rack
69
+ haml (4.0.6)
70
+ tilt
71
+ hashie (3.4.0)
72
+ highline (1.6.21)
73
+ hike (1.2.3)
74
+ hitimes (1.2.2)
75
+ hooks (0.4.0)
76
+ uber (~> 0.0.4)
77
+ i18n (0.7.0)
78
+ ice_nine (0.11.1)
79
+ inflecto (0.0.2)
80
+ json (1.8.2)
81
+ kramdown (1.6.0)
82
+ listen (2.9.0)
83
+ celluloid (>= 0.15.2)
84
+ rb-fsevent (>= 0.9.3)
85
+ rb-inotify (>= 0.9)
86
+ method_source (0.8.2)
87
+ middleman (3.3.10)
88
+ coffee-script (~> 2.2)
89
+ compass (>= 1.0.0, < 2.0.0)
90
+ compass-import-once (= 1.0.5)
91
+ execjs (~> 2.0)
92
+ haml (>= 4.0.5)
93
+ kramdown (~> 1.2)
94
+ middleman-core (= 3.3.10)
95
+ middleman-sprockets (>= 3.1.2)
96
+ sass (>= 3.4.0, < 4.0)
97
+ uglifier (~> 2.5)
98
+ middleman-core (3.3.10)
99
+ activesupport (~> 4.1.0)
100
+ bundler (~> 1.1)
101
+ erubis
102
+ hooks (~> 0.3)
103
+ i18n (~> 0.7.0)
104
+ listen (>= 2.7.9, < 3.0)
105
+ padrino-helpers (~> 0.12.3)
106
+ rack (>= 1.4.5, < 2.0)
107
+ rack-test (~> 0.6.2)
108
+ thor (>= 0.15.2, < 2.0)
109
+ tilt (~> 1.4.1, < 2.0)
110
+ middleman-sprockets (3.4.2)
111
+ middleman-core (>= 3.3)
112
+ sprockets (~> 2.12.1)
113
+ sprockets-helpers (~> 1.1.0)
114
+ sprockets-sass (~> 1.3.0)
115
+ mini_portile (0.6.2)
116
+ minitest (5.5.1)
117
+ multi_json (1.11.0)
118
+ multipart-post (2.0.0)
119
+ nokogiri (1.6.6.2)
120
+ mini_portile (~> 0.6.0)
121
+ octokit (3.8.0)
122
+ sawyer (~> 0.6.0, >= 0.5.3)
123
+ padrino-helpers (0.12.5)
124
+ i18n (~> 0.6, >= 0.6.7)
125
+ padrino-support (= 0.12.5)
126
+ tilt (~> 1.4.1)
127
+ padrino-support (0.12.5)
128
+ activesupport (>= 3.1)
129
+ pry (0.10.1)
130
+ coderay (~> 1.1.0)
131
+ method_source (~> 0.8.1)
132
+ slop (~> 3.4)
133
+ rack (1.6.0)
134
+ rack-test (0.6.3)
135
+ rack (>= 1.0)
136
+ rb-fsevent (0.9.4)
137
+ rb-inotify (0.9.5)
138
+ ffi (>= 0.5.0)
139
+ redcarpet (3.2.2)
140
+ sass (3.4.13)
141
+ sawyer (0.6.0)
142
+ addressable (~> 2.3.5)
143
+ faraday (~> 0.8, < 0.10)
144
+ slop (3.6.0)
145
+ sprockets (2.12.3)
146
+ hike (~> 1.2)
147
+ multi_json (~> 1.0)
148
+ rack (~> 1.0)
149
+ tilt (~> 1.1, != 1.3.0)
150
+ sprockets-helpers (1.1.0)
151
+ sprockets (~> 2.0)
152
+ sprockets-sass (1.3.1)
153
+ sprockets (~> 2.0)
154
+ tilt (~> 1.1)
155
+ thor (0.19.1)
156
+ thread_safe (0.3.5)
157
+ tilt (1.4.1)
158
+ timers (4.0.1)
159
+ hitimes
160
+ tzinfo (1.2.2)
161
+ thread_safe (~> 0.1)
162
+ uber (0.0.13)
163
+ uglifier (2.7.1)
164
+ execjs (>= 0.3.0)
165
+ json (>= 1.8.0)
166
+ virtus (1.0.4)
167
+ axiom-types (~> 0.1)
168
+ coercible (~> 1.0)
169
+ descendants_tracker (~> 0.0, >= 0.0.3)
170
+ equalizer (~> 0.0, >= 0.0.9)
171
+
172
+ PLATFORMS
173
+ ruby
174
+
175
+ DEPENDENCIES
176
+ brief!
177
+ middleman (~> 3.3.9)
178
+ pry
@@ -0,0 +1,16 @@
1
+ dir = Pathname(File.dirname(__FILE__))
2
+
3
+ config do
4
+ set(:docs_path, dir.join("documents"))
5
+ end
6
+
7
+ define "Page" do
8
+ meta do
9
+ title
10
+ end
11
+
12
+ content do
13
+ title "h1:first-of-type"
14
+ paragraphs "p"
15
+ end
16
+ end
@@ -0,0 +1 @@
1
+ activate :brief
@@ -0,0 +1,8 @@
1
+ ---
2
+ type: page
3
+ title: Page One
4
+ ---
5
+
6
+ # This is page one
7
+
8
+ This is incredible.
@@ -0,0 +1,8 @@
1
+ ---
2
+ type: page
3
+ title: Page Two
4
+ ---
5
+
6
+ # This is page two
7
+
8
+ This is super.
@@ -0,0 +1,6 @@
1
+
2
+ <% briefs.pages.each do |page| %>
3
+ <h1><%= page.title %></h1>
4
+ <p>This page has <%= page.paragraphs.length %> paragraphs</p>
5
+ <% end %>
6
+
@@ -0,0 +1,7 @@
1
+ <html>
2
+ <head>
3
+ </head>
4
+ <body>
5
+ <%= yield %>
6
+ </body>
7
+ </html>
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.7.2
4
+ version: 1.7.3
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-03-05 00:00:00.000000000 Z
11
+ date: 2015-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashie
@@ -100,14 +100,14 @@ dependencies:
100
100
  requirements:
101
101
  - - ">="
102
102
  - !ruby/object:Gem::Version
103
- version: '0'
103
+ version: '4.0'
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
- version: '0'
110
+ version: '4.0'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: redcarpet
113
113
  requirement: !ruby/object:Gem::Requirement
@@ -250,7 +250,7 @@ files:
250
250
  - examples/blog/docs/an-intro-to-brief.html.md
251
251
  - lib/.DS_Store
252
252
  - lib/brief.rb
253
- - lib/brief/adapters/middleman.rb
253
+ - lib/brief/adapters/middleman_extension.rb
254
254
  - lib/brief/apps.rb
255
255
  - lib/brief/briefcase.rb
256
256
  - lib/brief/cli/change.rb
@@ -330,6 +330,14 @@ files:
330
330
  - spec/spec_helper.rb
331
331
  - spec/support/test_helpers.rb
332
332
  - tasks/brief/release.rake
333
+ - tests/middleman/Gemfile
334
+ - tests/middleman/Gemfile.lock
335
+ - tests/middleman/brief.rb
336
+ - tests/middleman/config.rb
337
+ - tests/middleman/documents/pages/one.md
338
+ - tests/middleman/documents/pages/two.md
339
+ - tests/middleman/source/index.html.erb
340
+ - tests/middleman/source/layouts/layout.erb
333
341
  homepage: ''
334
342
  licenses:
335
343
  - MIT
@@ -1,17 +0,0 @@
1
- module Brief::Adapters
2
- class MiddlemanExtension
3
- def self.activate_brief_extension
4
- ::Middleman::Extensions.register(:brief, Brief::Adapters::MiddlemanExtension)
5
- end
6
-
7
- def initialize(app, options_hash = {}, &block)
8
- super
9
-
10
- app.include(ClassMethods)
11
-
12
- options_hash.each do |key, value|
13
- app.set(key, value)
14
- end
15
- end
16
- end
17
- end