redux_gen 0.1.3 → 0.2.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: b9d9917f17235f7bdae1b34ae648717b2c9fb488
4
- data.tar.gz: f1cc49730c0ec1a24974824ece0530032adb8f17
3
+ metadata.gz: 254c8606222f75ce4b34a4c97f4d9a1604478ce6
4
+ data.tar.gz: 3c041557d88664e7c9d9cc6ac944c9e13bbf290d
5
5
  SHA512:
6
- metadata.gz: 7a1f636e3644cfaa833640247f8bf87dd3a7d7ff830b99f1dbd6292026c4bafe6f66cda6d6918b72c3358255d1063e797dbf71b46ee42cf17330bf2a9fab150e
7
- data.tar.gz: c1e0fc9419f1086e1fd0dc3b1bf40c2d66f58fd5e5b090b45c3f27164c8d7607af2bf3471ff3169a8bc472b7bb4798891e626494f94b1814af3ab8867ad3410a
6
+ metadata.gz: 2f7f212484c57db9118570be4292f4aee610efe064bb8263bc41dc4a5a78ad6dc3e662ff12e24b60e294c36e4e736a7b3442f0c047659cff15da172c2a3eab9b
7
+ data.tar.gz: b1db935663fed3db092abcce6526ad052b214078c67b964445fa57e8afca8d3a71f0c8c87e77d3a78ed779510b870fce0c48efbbb0a75a996fa6e785b7e90c7d
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- redux_gen (0.1.3)
4
+ redux_gen (0.2.0)
5
5
  thor (~> 0.20.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -36,6 +36,14 @@ The `new` action accepts the component type and name of the component itself. Av
36
36
  Under the context of this generator, a component is any individual piece of React/Redux code that can be generated. Not to be confused with a React component
37
37
  which behaves like an HTML template.
38
38
 
39
+ To create a new component, ex. an action named foo:
40
+
41
+ ```
42
+ redux_gen new action foo
43
+ ```
44
+
45
+ This will generate a file `foo.js` within the `actions` directory. It will also create the `actions` directory if it doesn't already exist.
46
+
39
47
  ## Development
40
48
 
41
49
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -2,28 +2,25 @@ module ReduxGen
2
2
  class Template
3
3
  attr_accessor :name
4
4
 
5
- def self.template_directory
6
- File.expand_path("../../../template", __FILE__)
5
+ def initialize(component, name)
6
+ @renderer = Template.renderer_for component
7
+ @name = name
7
8
  end
8
9
 
9
- def self.validate component
10
- components = ["action", "component", "reducer", "middleware"]
11
- raise ArgumentError unless components.include? component
10
+ def render
11
+ @renderer.result(binding)
12
12
  end
13
13
 
14
- def self.path component
15
- "#{template_directory}/#{component}.js.erb"
14
+ def self.template_directory
15
+ File.expand_path("../../../template", __FILE__)
16
16
  end
17
17
 
18
- def initialize(component, name)
19
- Template.validate component
20
- raw_template = open(Template.path(component)).read
21
- @renderer = ERB.new(raw_template)
22
- @name = name
18
+ def self.path component
19
+ "#{template_directory}/#{component}.js.erb"
23
20
  end
24
21
 
25
- def render
26
- @renderer.result(binding)
22
+ def self.renderer_for component
23
+ ERB.new(open(Template.path(component)).read)
27
24
  end
28
25
  end
29
26
  end
@@ -0,0 +1,20 @@
1
+ module ReduxGen
2
+ module Validations
3
+ def self.validate component
4
+ components = ["action", "component", "reducer", "middleware"]
5
+ raise ArgumentError unless components.include? component
6
+ end
7
+
8
+ def self.directory component
9
+ component == "middleware" ? component : "#{component}s"
10
+ end
11
+
12
+ def self.validate_directory_for component
13
+ Dir.mkdir directory(component) unless Dir.exists? directory(component)
14
+ end
15
+
16
+ def self.component_path(component, name)
17
+ "#{directory(component)}/#{name}.js"
18
+ end
19
+ end
20
+ end
@@ -1,3 +1,3 @@
1
1
  module ReduxGen
2
- VERSION = "0.1.3"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/redux_gen.rb CHANGED
@@ -1,13 +1,18 @@
1
1
  require 'thor'
2
2
  require 'erb'
3
3
  require "redux_gen/version"
4
+ require "redux_gen/validations"
4
5
  require "redux_gen/template"
5
6
 
6
7
  module ReduxGen
7
8
  class CLI < Thor
8
9
  desc "new", "Create Redux components"
9
10
  def new(component, name)
11
+ Validations.validate component
12
+ Validations.validate_directory_for component
13
+ path = Validations.component_path(component, name)
10
14
  template = Template.new(component, name).render
15
+ open(path, 'w').write(template)
11
16
  end
12
17
  end
13
18
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redux_gen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Esteban Hernandez
@@ -88,6 +88,7 @@ files:
88
88
  - exe/redux_gen
89
89
  - lib/redux_gen.rb
90
90
  - lib/redux_gen/template.rb
91
+ - lib/redux_gen/validations.rb
91
92
  - lib/redux_gen/version.rb
92
93
  - redux_gen.gemspec
93
94
  - template/action.js.erb