brief 1.11.6 → 1.11.7

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: c777abc6c9fd2ef3ac8b46e526ea2ca0ad8dab05
4
- data.tar.gz: a334054f14e1227ce91bff94e1cdd7b4a7339c47
3
+ metadata.gz: fd687a96421413cf2b583197c999a635c776270f
4
+ data.tar.gz: a099d2c06a067176634a00a89b0277b3a57230fa
5
5
  SHA512:
6
- metadata.gz: 4ecf27b3d5f36288b54bd0cbd7a4dc142a95dacc22e0afc315f04141aed26e9e22fa0f7c62dce4bf1e57218fd023d1cacc5a5a78f148afc3871147cea756e3d7
7
- data.tar.gz: 20fa631cc45a9bbf33f51ecd97f1b001904eab11817dc0f376a2b5df2d47e196951bc07d1d65fa5228883758ba277949c364bdf5cf8cdaaf333cbc6ae09053b4
6
+ metadata.gz: 35eec77e8ba37daf91350e9a3b4a91c526ec02b4f2148c9058a002a2c2f993cc9048f8b8f7994521d40e3d18e4d92bfbc22e917c7d82d815852ff57135e27226
7
+ data.tar.gz: 75e7f2d9201a49d96262e7871bbdf3b1c4b2c373adca20b4ed68857e6e1ea57eaa30c669f8ee916bda98f01f0c646ffd31959284e91ebd7b577aa989e29ec6ce
data/CHANGELOG.md CHANGED
@@ -144,3 +144,7 @@ attributes.
144
144
  ### 1.9.12
145
145
  - Included ability to transform content using special markdown link syntax
146
146
  - Included ability to inline svg assets
147
+
148
+ ### 1.11.7
149
+ - Added ability to define briefcase commands and dispatch these
150
+ commands from the CLI
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- brief (1.11.5)
4
+ brief (1.11.7)
5
5
  activesupport (> 3.2)
6
6
  commander (~> 4.3)
7
7
  em-websocket (~> 0.5)
@@ -12,6 +12,7 @@ PATH
12
12
  hike (>= 1.2)
13
13
  inflecto (~> 0)
14
14
  nokogiri (~> 1.6)
15
+ terminal-table
15
16
  thin (= 1.6.3)
16
17
  virtus (~> 1.0)
17
18
 
@@ -91,6 +92,7 @@ GEM
91
92
  addressable (~> 2.3.5)
92
93
  faraday (~> 0.8, < 0.10)
93
94
  slop (3.6.0)
95
+ terminal-table (1.4.5)
94
96
  thin (1.6.3)
95
97
  daemons (~> 1.0, >= 1.0.9)
96
98
  eventmachine (~> 1.0)
@@ -21,6 +21,27 @@ module Brief
21
21
  Brief.cases[root.basename.to_s] ||= self
22
22
  end
23
23
 
24
+ # Runs a command
25
+ #
26
+ # Commands are defined in the briefcase configuration.
27
+ #
28
+ # You define a command by passing a block. This block will
29
+ # get called with the briefcase, and whatever other arguments
30
+ def run_command(name, *args)
31
+ if handler = Brief.commands.fetch(name.to_sym)
32
+ block = handler[:handler]
33
+ args.unshift(self)
34
+ block.call(*args)
35
+ else
36
+ raise 'Command not found'
37
+ end
38
+ end
39
+
40
+ # Returns a Hash object which presents some
41
+ # view of the briefcase. Accepts a params hash
42
+ # of options that will be passed to the presenter.
43
+ #
44
+ # The default presenter is Brief::Briefcase#as_default
24
45
  def present(style="default", params={})
25
46
  style = "default" if style.nil?
26
47
 
data/lib/brief/cli/run.rb CHANGED
@@ -1,3 +1,21 @@
1
+ command "run command" do |c|
2
+ c.syntax = 'brief run FILE'
3
+ c.description = 'run a script in the context of the briefcase'
4
+
5
+ c.action do |args, options|
6
+ command = args.first.to_s.to_sym
7
+
8
+ bc = Brief.case
9
+ bc = bc.call if bc.respond_to?(:call)
10
+
11
+ if !Brief.commands[command.to_sym]
12
+ puts "Invalid command. #{ Brief.commands.keys }"
13
+ else
14
+ bc.run_command(command.to_sym, *args)
15
+ end
16
+ end
17
+ end
18
+
1
19
  command "run" do |c|
2
20
  c.syntax = 'brief run FILE'
3
21
  c.description = 'run a script in the context of the briefcase'
@@ -2,6 +2,9 @@ command 'write' do |c|
2
2
  c.syntax = 'brief write MODEL_TYPE [OPTIONS]'
3
3
  c.description = 'Create a new document for a given model type'
4
4
 
5
+ # TODO
6
+ # We could potential query the available model classes we are aware of
7
+ # and determine which CLI arguments those model classes may ask for.
5
8
  c.action do |args, options|
6
9
  schema_map = Brief.case(true).schema_map(true)
7
10
  type_alias = args.first
@@ -10,6 +13,17 @@ command 'write' do |c|
10
13
  raise "Unknown model type: #{ type_alias }. Available types are: #{ schema_map.keys.join(',') }"
11
14
  end
12
15
 
16
+ # TODO
17
+ #
18
+ # We need to determine the initial content that gets put into the editor.
19
+ #
20
+ # Our options are:
21
+ #
22
+ # - use an example from the model, if one exists
23
+ # - deduce the content to use based on some combination of one or more of the items below:
24
+ # - specifics of the model
25
+ # - the state of the documents that exist for that model already
26
+ # - the arguments from the CLI
13
27
  default_example = "---\ntype:#{type_alias}\n---\n\n# Enter some content"
14
28
 
15
29
  content = ask_editor(model_class.to_mash.example || default_example)
data/lib/brief/dsl.rb CHANGED
@@ -6,10 +6,27 @@ module Brief
6
6
  Brief::Configuration.instance.instance_eval(&block) if block_given?
7
7
  end
8
8
 
9
+ # Define a view of the briefcase. Pass a block
10
+ # which returns a hash that displays the desired
11
+ # content
9
12
  def view(name, &block)
10
13
  Brief.views[name.to_sym] = block
11
14
  end
12
15
 
16
+ # Register a new command for this briefcase.
17
+ #
18
+ # Pass the name of the command, options, and a block.
19
+ #
20
+ # The block will get called with the briefcase, and any arguments
21
+ #
22
+ # currently doesn't accept any options
23
+ def command(name, options={}, &block)
24
+ Brief.commands[name.to_sym] = {
25
+ options: options,
26
+ handler: block
27
+ }
28
+ end
29
+
13
30
  # Extends an existing class
14
31
  def extend(*args, &block)
15
32
  options = args.dup.extract_options!
data/lib/brief/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Brief
2
- VERSION = '1.11.6'
2
+ VERSION = '1.11.7'
3
3
  end
data/lib/brief.rb CHANGED
@@ -45,10 +45,15 @@ module Brief
45
45
  end
46
46
  end
47
47
 
48
+
48
49
  def self.views
49
50
  @views ||= {}
50
51
  end
51
52
 
53
+ def self.commands
54
+ @commands ||= {}
55
+ end
56
+
52
57
  def self.environment_info
53
58
  {
54
59
  VERSION: Brief::VERSION,
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.11.6
4
+ version: 1.11.7
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-06-06 00:00:00.000000000 Z
11
+ date: 2015-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hashie