diecut 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 107febe45026dd5f8483a22c823ff7df081d9376
4
- data.tar.gz: 3ad4f743f9aaa20bbe24a5c72a31d4c1ef813048
3
+ metadata.gz: 050a46989b178da905def8fbfb34438d55420670
4
+ data.tar.gz: 0d78911f4ba8eff62a23771eac548fc972ec0459
5
5
  SHA512:
6
- metadata.gz: 4d6837550e1a368a23781bfdd8c0b66450ad3ed19f6d831102cc9b4541285dbdbe4cf45010fa7b767a3babdc29fb78ddff405dfd89d5c5cfa289a5dd6903549f
7
- data.tar.gz: 450068202354f5fe74a57f309beeaeb08e11c2eceb4adeb74ca8083d2570679333567d449b616e750146cbf06041d1f363e22f8945b955dff4c5db940c0d4b4d
6
+ metadata.gz: 95b1f40f8bae335f41412543b63865870590b824606660fa3cd509202725093b13720f2cb1439b02bf4561e6014508363d53187c38302d3cb46122d7ec40e7ab
7
+ data.tar.gz: 0b7b55d6b626fc9c0e55eac32e8229909f768f8f3651d83d3acf4444d1a131da2bb9d088e63fa25a6c282d11b4bd6084086bc6dc4cc9a52fb9caf325fc434f0d
data/lib/diecut/cli.rb CHANGED
@@ -15,7 +15,7 @@ module Diecut
15
15
  end
16
16
 
17
17
  mediator.plugins.each do |plugin|
18
- class_option "with-#{plugin.name}", :default => plugin.default_active?
18
+ class_option "with-#{plugin.name}", :default => plugin.default_activated_for(kind)
19
19
  end
20
20
 
21
21
  setup_subclass(mediator, example_ui)
@@ -48,8 +48,10 @@ module Diecut
48
48
  mill.activate_plugins {|name| options["with-#{name}"] }
49
49
 
50
50
  ui = mill.user_interface
51
- options.delete_if{|_, value| value.nil?}
52
- ui.from_hash(options)
51
+ ui_hash = Hash[ options.find_all do |name, value|
52
+ not value.nil?
53
+ end]
54
+ ui.from_hash(ui_hash)
53
55
 
54
56
  mill.churn(ui) do |path, contents|
55
57
  create_file(path, contents)
data/lib/diecut/errors.rb CHANGED
@@ -13,6 +13,10 @@ module Diecut
13
13
  "Default on #{context_path.inspect} from plugin #{name} has both a simple default value (#{value}) and a dynamic block value, which isn't allowed."
14
14
  end
15
15
 
16
+ def unregistered_plugin_source_message(source_path)
17
+ "Couldn't find source of plugin which appears to be defined at #{source_path}"
18
+ end
19
+
16
20
  def missing_context_field(plugin_name, option_name, context_path)
17
21
  issue(missing_context_field_message(option_name, context_path))
18
22
  end
@@ -25,6 +29,10 @@ module Diecut
25
29
  issue invalid_plugin_message(name, context_path, value)
26
30
  end
27
31
 
32
+ def unregistered_plugin_source(source_path)
33
+ issue unregistered_plugin_source_message(source_path)
34
+ end
35
+
28
36
  def handle_exception(ex)
29
37
  if Error === ex
30
38
  issue(ex.message)
@@ -56,6 +64,10 @@ module Diecut
56
64
  raise
57
65
  end
58
66
 
67
+ def unregistered_plugin_source(source_path)
68
+ raise UnregisteredPluginSource, unregistered_plugin_source_message(source_path)
69
+ end
70
+
59
71
  def missing_context_field(option_name, context_path)
60
72
  raise MissingContext, missing_context_field_message(option_name, context_path)
61
73
  end
@@ -80,4 +92,5 @@ module Diecut
80
92
  class OverriddenDefault < Error; end
81
93
  class InvalidPlugin < Error; end
82
94
  class FieldClash < Error; end
95
+ class UnregisteredPluginSource < Error; end
83
96
  end
@@ -11,8 +11,8 @@ module Diecut
11
11
  end
12
12
  attr_reader :plugins
13
13
 
14
- def add_plugin(plug)
15
- @activated[plug.name] = plug.default_activated
14
+ def add_plugin(plug, activated)
15
+ @activated[plug.name] = activated
16
16
  @plugins << plug
17
17
  end
18
18
 
data/lib/diecut/mill.rb CHANGED
@@ -37,7 +37,13 @@ module Diecut
37
37
  end
38
38
  Valise::Set.define do
39
39
  stems.each do |stem|
40
- ro stem.template_dir
40
+ if stem.stem
41
+ stemmed(stem.stem) do
42
+ ro stem.template_dir
43
+ end
44
+ else
45
+ ro stem.template_dir
46
+ end
41
47
  end
42
48
  end
43
49
  end
@@ -8,7 +8,15 @@ module Diecut
8
8
  include CallerLocationsPolyfill
9
9
  NO_VALUE = Object.new.freeze
10
10
 
11
- KindStem = Struct.new(:kind, :stem, :template_dir)
11
+ class KindStem < Struct.new(:kind, :stem, :template_dir, :default_activated)
12
+ def default_off
13
+ self.default_activated = false
14
+ end
15
+
16
+ def default_on
17
+ self.default_activated = true
18
+ end
19
+ end
12
20
 
13
21
  def initialize(name, source_path)
14
22
  @name = name
@@ -39,6 +47,15 @@ module Diecut
39
47
  @kind_stems.key?(kind)
40
48
  end
41
49
 
50
+ def default_activated_for(kind)
51
+ stem = @kind_stems[kind]
52
+ if stem.default_activated.nil?
53
+ default_active?
54
+ else
55
+ stem.default_activated
56
+ end
57
+ end
58
+
42
59
  def default_active?
43
60
  @default_activated
44
61
  end
@@ -71,10 +88,12 @@ module Diecut
71
88
  #
72
89
  #
73
90
  def for_kind(kind, templates = nil, stem = nil)
74
- stem ||= [kind]
75
91
  templates ||= "diecut_templates"
76
92
  templates = File.expand_path(templates, File.dirname(caller_locations(1..1).first.absolute_path))
77
- @kind_stems[kind] = KindStem.new(kind, stem, templates)
93
+ kind_stem = KindStem.new(kind, stem, templates, nil)
94
+ @kind_stems[kind] = kind_stem
95
+ yield kind_stem if block_given?
96
+ return kind_stem
78
97
  end
79
98
 
80
99
  # Force this plugin to be enabled to be used. Good for optional features.
@@ -118,7 +137,6 @@ module Diecut
118
137
  end
119
138
  if value != NO_VALUE and not block.nil?
120
139
  issue_handler.invalid_plugin(name, context_path, value)
121
- raise InvalidPlugin, "Default on #{name.inspect} both has a simple default value (#{value}) and a dynamic block value, which isn't allowed."
122
140
  end
123
141
  @context_defaults << ContextDefault.new(context_path, value, block)
124
142
  end
@@ -32,6 +32,11 @@ module Diecut
32
32
  end
33
33
  end
34
34
 
35
+ def issue_handler
36
+ @issue_handler ||= Diecut.issue_handler
37
+ end
38
+ attr_writer :issue_handler
39
+
35
40
  # :nocov:
36
41
  def latest_specs(prerelease)
37
42
  Gem::Specification.latest_specs(prerelease)
@@ -170,7 +175,9 @@ module Diecut
170
175
  return path
171
176
  end
172
177
  end
173
- raise "Couldn't find source of plugin..."
178
+ fallback_location = locations.first.absolute_path
179
+ issue_handler.unregistered_plugin_source(fallback_location)
180
+ return fallback_location
174
181
  end
175
182
 
176
183
  def add_plugin_desc(desc)
data/lib/diecut.rb CHANGED
@@ -5,6 +5,18 @@ require 'diecut/errors'
5
5
 
6
6
  module Diecut
7
7
  class << self
8
+ # Used in a `diecut_plugin.rb` file (either in the `lib/` of a gem, or at
9
+ # the local `~/.config/diecut/diecut_plugin.rb` to register a new plugin.
10
+ #
11
+ # @param name [String, Symbol]
12
+ # Names the plugin so that it can be toggled later
13
+ #
14
+ # @yieldparam description [PluginDescription]
15
+ # The description object to configure the plugin with.
16
+ def plugin(name, &block)
17
+ plugin_loader.describe_plugin(name, &block)
18
+ end
19
+
8
20
  def plugin_loader
9
21
  @plugin_loader ||= PluginLoader.new
10
22
  end
@@ -30,18 +42,6 @@ module Diecut
30
42
  end
31
43
  attr_writer :issue_handler
32
44
 
33
- # Used in a `diecut_plugin.rb` file (either in the `lib/` of a gem, or at
34
- # the local `~/.config/diecut/diecut_plugin.rb` to register a new plugin.
35
- #
36
- # @param name [String, Symbol]
37
- # Names the plugin so that it can be toggled later
38
- #
39
- # @yieldparam description [PluginDescription]
40
- # The description object to configure the plugin with.
41
- def plugin(name, &block)
42
- plugin_loader.describe_plugin(name, &block)
43
- end
44
-
45
45
  def kinds
46
46
  plugins.reduce([]) do |list, plugin|
47
47
  list + plugin.kinds
@@ -52,7 +52,7 @@ module Diecut
52
52
  Mediator.new.tap do |med|
53
53
  plugins.each do |plug|
54
54
  next unless plug.has_kind?(kind)
55
- med.add_plugin(plug)
55
+ med.add_plugin(plug, plug.default_activated_for(kind))
56
56
  end
57
57
  end
58
58
  end
data/spec/linter_spec.rb CHANGED
@@ -59,7 +59,7 @@ describe Diecut::Mill do
59
59
  allow(Diecut).to receive(:plugin_loader).and_return(loader)
60
60
 
61
61
  plugins.each do |plugin|
62
- mill.mediator.add_plugin(plugin)
62
+ mill.mediator.add_plugin(plugin, plugin.default_active?)
63
63
  end
64
64
  end
65
65
 
data/spec/mill_spec.rb CHANGED
@@ -31,8 +31,8 @@ describe Diecut::Mill do
31
31
  end
32
32
 
33
33
  before :each do
34
- mill.mediator.add_plugin(plugin)
35
- mill.mediator.add_plugin(other_plugin)
34
+ mill.mediator.add_plugin(plugin, true)
35
+ mill.mediator.add_plugin(other_plugin, true)
36
36
  end
37
37
 
38
38
  it "should render files" do
@@ -8,6 +8,8 @@ describe "Diecut.plugin" do
8
8
  end
9
9
 
10
10
  before :each do
11
+ Diecut.clear_plugins
12
+
11
13
  Diecut.plugin_loader = loader
12
14
  Diecut.plugin("test") do |plugin|
13
15
  plugin.for_kind("app")
data/spec/spec_helper.rb CHANGED
@@ -2,6 +2,7 @@ require 'cadre/rspec3'
2
2
 
3
3
  RSpec.configure do |config|
4
4
  config.run_all_when_everything_filtered = true
5
+ config.example_status_persistence_file_path = "example_results.txt"
5
6
  config.add_formatter(Cadre::RSpec3::NotifyOnCompleteFormatter)
6
7
  config.add_formatter(Cadre::RSpec3::QuickfixFormatter)
7
8
 
@@ -0,0 +1,78 @@
1
+ require 'diecut/mill'
2
+ require 'file-sandbox'
3
+
4
+ describe Diecut::Mill do
5
+ include FileSandbox
6
+ before :each do
7
+ Diecut.clear_plugins
8
+
9
+ sandbox["resource/src/common/resources/{{resource_name}}.js"].contents = "yup"
10
+ sandbox["mappers/app/mappers/{{mapper_name}}.rb"].contents = "yup"
11
+ end
12
+
13
+ before :each do
14
+ Diecut.plugin("relayer-resource") do |resource|
15
+ resource.for_kind("xing", File.join(sandbox.root, "resource")) do |xing|
16
+ xing.stem = 'frontend'
17
+ end
18
+
19
+ resource.for_kind('angular-one', File.join(sandbox.root, "resource")) do |ng|
20
+ ng.default_off
21
+ end
22
+ end
23
+ end
24
+
25
+ before :each do
26
+ Diecut.plugin("rails-mapper") do |mapper|
27
+ mapper.for_kind("xing", File.join(sandbox.root, "mappers")) do |xing|
28
+ xing.stem = 'backend'
29
+ end
30
+
31
+ mapper.for_kind('rails', File.join(sandbox.root, "mappers"))
32
+ end
33
+ end
34
+
35
+ after :each do
36
+ Diecut.clear_plugins
37
+ end
38
+
39
+ let :path_list do
40
+ mill.load_files
41
+ mill.templates.templates.map{|n, template| template.path}
42
+ end
43
+
44
+ describe "Mixed with stems" do
45
+ let :mill do
46
+ Diecut::Mill.new("xing")
47
+ end
48
+
49
+ it "should have files in stemmed directories" do
50
+ expect(path_list).to include("frontend/src/common/resources/{{resource_name}}.js", "backend/app/mappers/{{mapper_name}}.rb")
51
+ end
52
+ end
53
+
54
+ describe "Simpler kind" do
55
+ let :mill do
56
+ Diecut::Mill.new("rails")
57
+ end
58
+
59
+ it "should have files in stemmed directories" do
60
+ expect(path_list).to include("app/mappers/{{mapper_name}}.rb")
61
+ end
62
+ end
63
+
64
+ describe "Simpler, but defaults off for kind" do
65
+ let :mill do
66
+ Diecut::Mill.new("angular-one")
67
+ end
68
+
69
+ it "should have files in stemmed directories" do
70
+ expect(path_list).to eq([])
71
+ end
72
+
73
+ it "should get the files if enables" do
74
+ mill.activate_plugins{ true }
75
+ expect(path_list).to include("src/common/resources/{{resource_name}}.js")
76
+ end
77
+ end
78
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: diecut
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Judson Lester
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-03 00:00:00.000000000 Z
11
+ date: 2016-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mustache
@@ -80,7 +80,10 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0.8'
83
- description: ''
83
+ description: |2
84
+ Diecut is a tool for supporting the process of writing code generation. It provides
85
+ linting, a general purpose command line generator, discovery of templated values, and
86
+ composed generation.
84
87
  email:
85
88
  - nyarly@gmail.com
86
89
  executables:
@@ -127,6 +130,7 @@ files:
127
130
  - spec/plugin_loader_spec.rb
128
131
  - spec/register_plugin_spec.rb
129
132
  - spec/spec_helper.rb
133
+ - spec/stemming_kinds_spec.rb
130
134
  - spec/template-reducer_spec.rb
131
135
  - spec/template_set_spec.rb
132
136
  - spec/template_spec.rb
@@ -140,7 +144,7 @@ rdoc_options:
140
144
  - "--main"
141
145
  - doc/README
142
146
  - "--title"
143
- - diecut-0.0.3 Documentation
147
+ - diecut-0.0.4 Documentation
144
148
  require_paths:
145
149
  - lib/
146
150
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -158,6 +162,6 @@ rubyforge_project: diecut
158
162
  rubygems_version: 2.4.8
159
163
  signing_key:
160
164
  specification_version: 4
161
- summary: ''
165
+ summary: Code generation support tools
162
166
  test_files:
163
167
  - gem_test_suite.rb