diecut 0.0.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.
@@ -0,0 +1,105 @@
1
+ require 'diecut'
2
+
3
+ describe "Diecut.plugin" do
4
+ let :loader do
5
+ Diecut::PluginLoader.new.tap do |loader|
6
+ allow(loader).to receive(:choose_source).and_return("dont/care/where")
7
+ end
8
+ end
9
+
10
+ before :each do
11
+ Diecut.plugin_loader = loader
12
+ Diecut.plugin("test") do |plugin|
13
+ plugin.for_kind("app")
14
+ plugin.default_off
15
+
16
+ plugin.default(%w(budgies count), 10)
17
+ plugin.default(%w(budgies birthday)) do |context|
18
+ Time.now
19
+ end
20
+
21
+ plugin.option(:alive) do |alive|
22
+ alive.description "Are the budgies alive?"
23
+ alive.goes_to("budgies", "living")
24
+ end
25
+
26
+ plugin.option(:name_seed) do |name|
27
+ name.description "Used to name all the budgies"
28
+ name.default "Bruce"
29
+ end
30
+
31
+ plugin.resolve do |ui, context|
32
+ context.budgies.names = context.budgies.count.times.map do |idx|
33
+ "#{ui.name_seed} ##{idx}"
34
+ end
35
+ end
36
+ end
37
+ end
38
+
39
+ after :each do
40
+ Diecut.clear_plugins
41
+ end
42
+
43
+ let :context_class do
44
+ budgie_class = Class.new(Diecut::Configurable) do
45
+ setting :count
46
+ setting :birthday
47
+ setting :living
48
+ setting :names
49
+ end
50
+
51
+ Class.new(Diecut::Configurable) do
52
+ setting :budgies, budgie_class
53
+ end
54
+ end
55
+
56
+ let :mediator do
57
+ Diecut.mediator("app")
58
+ end
59
+
60
+ it "should activate and deactivate plugins" do
61
+ expect(mediator.activated?("test")).to eq false
62
+ mediator.activate("test")
63
+ expect(mediator.activated?("test")).to eq true
64
+ mediator.deactivate("test")
65
+ expect(mediator.activated?("test")).to eq false
66
+ end
67
+
68
+ it "should process the whole thing" do
69
+ mediator.activate("test")
70
+ ui_class = mediator.build_ui_class(context_class)
71
+
72
+ expect(ui_class.field_names).to contain_exactly(:name_seed, :alive)
73
+ expect(ui_class.required?(:name_seed)).to eq false
74
+ expect(ui_class.default_for(:name_seed)).to eq "Bruce"
75
+ expect(ui_class.required?(:alive)).to eq true
76
+ expect(ui_class.description(:alive)).to match(/alive\?/)
77
+
78
+ ui = ui_class.new
79
+
80
+ ui.alive = true
81
+ ui.name_seed = "Jane"
82
+
83
+ context = mediator.apply_user_input(ui, context_class)
84
+
85
+ expect(context.budgies.count).to eq 10
86
+ expect(context.budgies.birthday).to be_a(Time)
87
+ expect(context.budgies.living).to eq true
88
+ expect(context.budgies.names.length).to eq 10
89
+ expect(context.budgies.names).to include("Jane #3")
90
+ end
91
+
92
+ it "should produce an example UI" do
93
+ ui_class = mediator.build_example_ui
94
+ expect(ui_class.field_names).to contain_exactly(:name_seed, :alive)
95
+ expect(ui_class.required?(:name_seed)).to eq false
96
+ expect(ui_class.required?(:alive)).to eq true
97
+ expect(ui_class.description(:alive)).to match(/alive\?/)
98
+ end
99
+
100
+ it "should leave out options for deactivated plugins" do
101
+ expect(mediator.activated?("test")).to eq false
102
+ ui_class = mediator.build_ui_class(context_class)
103
+ expect(ui_class.field_names).to be_empty
104
+ end
105
+ end
@@ -0,0 +1,12 @@
1
+ require 'cadre/rspec3'
2
+
3
+ RSpec.configure do |config|
4
+ config.run_all_when_everything_filtered = true
5
+ config.add_formatter(Cadre::RSpec3::NotifyOnCompleteFormatter)
6
+ config.add_formatter(Cadre::RSpec3::QuickfixFormatter)
7
+
8
+ config.mock_with(:rspec) do |mock|
9
+ mock.verify_partial_doubles = true
10
+ mock.verify_doubled_constant_names = true
11
+ end
12
+ end
@@ -0,0 +1,36 @@
1
+ require 'mustache'
2
+ require 'diecut/template-reducer'
3
+
4
+ describe Diecut::TemplateReducer do
5
+ let :tmpl_string do
6
+ <<EOT
7
+ I am a {{thing}} with {{ very.deep.values }}.
8
+ {{#sometimes}}I tell secrets {{#lengthy?}}at length{{/lengthy?}} - also {{sometime}}{{/sometimes}}
9
+ {{^sometimes}}I am an open book{{/sometimes}}{{! this is silly }}
10
+ Oh: something else: {{< apartial}}
11
+ This too: {{#nested}}{{< apartial}}{{/nested}}
12
+ EOT
13
+ end
14
+
15
+ let :reducer do
16
+ Diecut::TemplateReducer.new(Mustache::Parser.new.compile(tmpl_string))
17
+ end
18
+
19
+ it "extracts all the fields" do
20
+ expect(reducer.fields).to contain_exactly(%w[thing], %w[very deep values],
21
+ %w[nested], %w[sometimes], %w[sometimes lengthy?], %w[sometimes sometime])
22
+ end
23
+
24
+ it "filters leaf fields" do
25
+ expect(reducer.leaf_fields).to contain_exactly(%w[thing], %w[very deep values],
26
+ %w[nested], %w[sometimes lengthy?], %w[sometimes sometime])
27
+ end
28
+
29
+ it "extracts all the sections" do
30
+ expect(reducer.sections).to contain_exactly(%w[sometimes], %w[sometimes lengthy?], %w[nested])
31
+ end
32
+
33
+ it "extracts all the partials" do
34
+ expect(reducer.partials).to contain_exactly(["apartial", []], ["apartial", ["nested"]])
35
+ end
36
+ end
@@ -0,0 +1,22 @@
1
+ require 'diecut/template-set'
2
+
3
+ describe Diecut::TemplateSet do
4
+ subject :template_set do
5
+ Diecut::TemplateSet.new
6
+ end
7
+
8
+ it "should render files" do
9
+ template_set.add "{{testing}}.txt", "I am a {{thing}} for {{testing}}"
10
+ template_set.prepare
11
+ template_set.context = template_set.context_class.new
12
+
13
+ template_set.context.setup_defaults
14
+ template_set.context.testing = "checking"
15
+ template_set.context.thing = "test file"
16
+
17
+ template_set.results do |path, contents|
18
+ expect(path).to eq "checking.txt"
19
+ expect(contents).to eq "I am a test file for checking"
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,60 @@
1
+ require 'diecut/template'
2
+ require 'diecut/mustache'
3
+
4
+ describe Diecut::Template do
5
+ let :tmpl do
6
+ tmpl = Diecut::Template.new("somewhere", <<EOT)
7
+ I am a {{thing}} with {{ very.deep.values }}.
8
+ {{#sometimes}}I tell secrets {{#lengthy}}at length {{/lengthy}}- also {{sometime}}
9
+ {{/sometimes}}
10
+ {{^sometimes}}I am an open book{{/sometimes}}{{! this is silly }}
11
+ Oh: something else: {{< apartial}}
12
+ This too: {{#nested}}{{< apartial}}{{/nested}}
13
+ EOT
14
+ tmpl
15
+ end
16
+
17
+ let :prtl do
18
+ Diecut::Template.new("apartial", <<EOT)
19
+ I'm {{status}}
20
+ EOT
21
+ end
22
+
23
+ let :renderer do
24
+ renderer = Diecut::Mustache.new
25
+ renderer.partials_hash = {
26
+ :somewhere => tmpl,
27
+ :apartial => prtl
28
+ }
29
+ renderer
30
+ end
31
+
32
+ before :each do
33
+ tmpl.partial_context(prtl)
34
+
35
+ tmpl.context.from_hash(
36
+ thing: "template",
37
+ very: { deep: { values: "strongly held beliefs" }},
38
+ sometimes: [
39
+ { sometime: "stories", lengthy: false },
40
+ { sometime: "lies", lengthy: true }
41
+ ],
42
+ status: "green",
43
+ nested: { status: "yellow" }
44
+ )
45
+ end
46
+
47
+ it "renders a string based on config" do
48
+
49
+ expect(tmpl.render(renderer)).to eq(<<EOS)
50
+ I am a template with strongly held beliefs.
51
+ I tell secrets - also stories
52
+ I tell secrets at length - also lies
53
+
54
+ Oh: something else: I'm green
55
+
56
+ This too: I'm yellow
57
+
58
+ EOS
59
+ end
60
+ end
metadata ADDED
@@ -0,0 +1,152 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: diecut
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Judson Lester
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-02-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: mustache
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">"
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">"
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: calibrate
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">"
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: valise
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">"
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">"
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: thor
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">"
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">"
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: paint
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">"
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">"
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: ''
84
+ email:
85
+ - nyarly@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - bin/diecut
91
+ - gem_test_suite.rb
92
+ - lib/diecut.rb
93
+ - lib/diecut/caller-locations-polyfill.rb
94
+ - lib/diecut/cli.rb
95
+ - lib/diecut/configurable.rb
96
+ - lib/diecut/context-handler.rb
97
+ - lib/diecut/errors.rb
98
+ - lib/diecut/linter.rb
99
+ - lib/diecut/mediator.rb
100
+ - lib/diecut/mill.rb
101
+ - lib/diecut/mustache.rb
102
+ - lib/diecut/plugin-description.rb
103
+ - lib/diecut/plugin-description/context-default.rb
104
+ - lib/diecut/plugin-description/option.rb
105
+ - lib/diecut/plugin-loader.rb
106
+ - lib/diecut/report.rb
107
+ - lib/diecut/template-reducer.rb
108
+ - lib/diecut/template-set.rb
109
+ - lib/diecut/template.rb
110
+ - lib/diecut/ui-applier.rb
111
+ - lib/diecut/ui-config.rb
112
+ - spec/cli_spec.rb
113
+ - spec/configurable_spec.rb
114
+ - spec/linter_spec.rb
115
+ - spec/mill_spec.rb
116
+ - spec/plugin_loader_spec.rb
117
+ - spec/register_plugin_spec.rb
118
+ - spec/spec_helper.rb
119
+ - spec/template-reducer_spec.rb
120
+ - spec/template_set_spec.rb
121
+ - spec/template_spec.rb
122
+ homepage: http://nyarly.github.com/diecut
123
+ licenses:
124
+ - MIT
125
+ metadata: {}
126
+ post_install_message:
127
+ rdoc_options:
128
+ - "--inline-source"
129
+ - "--main"
130
+ - doc/README
131
+ - "--title"
132
+ - diecut-0.0.1 Documentation
133
+ require_paths:
134
+ - lib/
135
+ required_ruby_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ required_rubygems_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ requirements: []
146
+ rubyforge_project: diecut
147
+ rubygems_version: 2.4.8
148
+ signing_key:
149
+ specification_version: 4
150
+ summary: ''
151
+ test_files:
152
+ - gem_test_suite.rb