redux_gen 0.2.1 → 0.3.0

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: 712045449b8613b4ae9236640a5ad2b04f871aec
4
- data.tar.gz: d6884d1933f6833213386cfb48be46c27f26e26b
3
+ metadata.gz: 5afd57bddd4117bcb86a648a4e3c82aa6fce07f4
4
+ data.tar.gz: c15670b5b82514e6b80735d2e7be101797dde058
5
5
  SHA512:
6
- metadata.gz: 0da03aae73c0d8597f5e18cdf4c6af2d4928db5aa4d46851d625026406a602202a174bca89b0ec7cf216c9369e24cae5fe0068aa35c749afd6c5355f910f87a6
7
- data.tar.gz: 89796feb12cef351fe4137ad56676d19e2d70aed06f5b20ebecb326f379018fdadda54579d9ab3622694716a78d6accd3f73dc711c5b1ff73b7cf1544a535807
6
+ metadata.gz: 22e9d389d03f18e769f649ef2cea09870543916eef0e35b2f749b03423c2356c3561af07a6959f08b92f44ae857cf5b2f87a2414481bbfe340cf6647d685badc
7
+ data.tar.gz: 55a1717a55953d9ec8d31d0d0f69973eb8fe322dabb07525bd807742ed92609e565177ddb6357c3c58087da4273b9e8c4459e5c162957d8800131c099aee290a
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- redux_gen (0.2.1)
4
+ redux_gen (0.3.0)
5
5
  thor (~> 0.20.0)
6
6
 
7
7
  GEM
data/lib/redux_gen.rb CHANGED
@@ -10,11 +10,29 @@ module ReduxGen
10
10
  def new(component, name)
11
11
  Validations.validate component
12
12
  Validations.validate_directory_for component
13
- path = Validations.component_path component, name
14
- template = Template.new(component, name).render
13
+ Validations.validate_test_directory_for component
14
+ make component, name
15
+ make_test component, name
16
+ end
17
+
18
+ private
19
+
20
+ def write_out(path, content)
15
21
  open(path, 'w') do |output|
16
- output.write template
22
+ output.write content
17
23
  end
18
24
  end
25
+
26
+ def make(component, name)
27
+ path = Validations.component_path component, name
28
+ template = Template.new(component, name).render
29
+ write_out(path, template)
30
+ end
31
+
32
+ def make_test(component, name)
33
+ test_path = Validations.test_path component, name
34
+ test_template = Template.new(component, name, test: true).render
35
+ write_out(test_path, test_template)
36
+ end
19
37
  end
20
38
  end
@@ -2,8 +2,8 @@ module ReduxGen
2
2
  class Template
3
3
  attr_accessor :name
4
4
 
5
- def initialize(component, name)
6
- @renderer = Template.renderer_for component
5
+ def initialize(component, name, test: false)
6
+ @renderer = Template.renderer_for component, test: test
7
7
  @name = Validations.sanitize component, name
8
8
  end
9
9
 
@@ -19,8 +19,13 @@ module ReduxGen
19
19
  "#{template_directory}/#{component}.js.erb"
20
20
  end
21
21
 
22
- def self.renderer_for component
23
- ERB.new(open(Template.path(component)).read)
22
+ def self.test_path component
23
+ "#{template_directory}/#{component}.spec.js.erb"
24
+ end
25
+
26
+ def self.renderer_for component, test: false
27
+ path = test ? Template.test_path(component) : Template.path(component)
28
+ ERB.new(open(path).read)
24
29
  end
25
30
  end
26
31
  end
@@ -9,14 +9,28 @@ module ReduxGen
9
9
  component == "middleware" ? component : "#{component}s"
10
10
  end
11
11
 
12
+ def self.test_directory component
13
+ "#{directory(component)}/tests"
14
+ end
15
+
12
16
  def self.validate_directory_for component
13
17
  Dir.mkdir directory(component) unless Dir.exists? directory(component)
14
18
  end
15
19
 
20
+ def self.validate_test_directory_for component
21
+ unless Dir.exists? test_directory(component)
22
+ Dir.mkdir test_directory(component)
23
+ end
24
+ end
25
+
16
26
  def self.component_path(component, name)
17
27
  "#{directory(component)}/#{sanitize(component, name)}.js"
18
28
  end
19
29
 
30
+ def self.test_path(component, name)
31
+ "#{directory(component)}/tests/#{sanitize(component, name)}.spec.js"
32
+ end
33
+
20
34
  def self.sanitize component, name
21
35
  first = name.split.first
22
36
  rest = name.split[1..-1].map(&:capitalize).join
@@ -1,3 +1,3 @@
1
1
  module ReduxGen
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redux_gen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Esteban Hernandez
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-10-12 00:00:00.000000000 Z
11
+ date: 2017-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler