Skip to content

Commit 2e8da21

Browse files
update component generator according to jonas' feedback
1 parent 433bbe8 commit 2e8da21

File tree

4 files changed

+22
-49
lines changed

4 files changed

+22
-49
lines changed
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
Description:
2-
Explain the generator
2+
Generates matestack components to app/matestack/components
33

44
Example:
5-
rails generate matestack_component Thing
5+
rails generate matestack_component NAME --(no-)dynamic --(no-)haml --(no-)scss
66

77
This will create:
8-
what/will/it/create
8+
app/matestack/components/NAME.rb
9+
(app/matestack/components/NAME.js if --dynamic)
10+
(app/matestack/components/NAME.haml if --haml)
11+
(app/matestack/components/NAME.scss if --scss)

lib/generators/matestack_component/matestack_component_generator.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,26 @@ class MatestackComponentGenerator < Rails::Generators::NamedBase
22
source_root File.expand_path('templates', __dir__)
33

44
class_option :dynamic, type: :boolean, default: false
5+
class_option :scss, type: :boolean, default: false
6+
class_option :haml, type: :boolean, default: false
57
class_option :namespace, type: :string
68

79
def create_matestack_component
810
@dynamic = options[:dynamic]
911
@namespace = options[:namespace]
1012

11-
to_be_created_files = ['.rb', '.haml', '.scss']
12-
to_be_created_files << '.js' if @dynamic == true
13+
# Future: Check for matestack-compatible namespacing!
14+
15+
to_be_created_files = ['.rb']
16+
to_be_created_files << '.js' if options[:dynamic]
17+
to_be_created_files << '.scss' if options[:scss]
18+
to_be_created_files << '.haml' if options[:haml]
1319

1420
matestack_component_dir_path = "app/matestack/components/"
1521
matestack_component_dir_path << "#{@namespace}/" unless @namespace.nil?
16-
# matestack_component_dir_path << "#{file_name}"
1722

1823
to_be_created_files.each do |file|
1924
generator_path = matestack_component_dir_path + "/#{file_name}#{file}"
20-
2125
template "matestack_component#{file}.erb", generator_path
2226
end
2327

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,12 @@
1-
// this component is way overblown. Make sure to delete everything you don't need, mate!
2-
3-
import Vue from 'vue/dist/vue.esm'
4-
import Vuex from 'vuex'
5-
import axios from 'axios'
6-
7-
import matestackEventHub from 'core/js/event-hub'
8-
9-
import componentMixin from 'component/js/component'
10-
11-
const componentDef = {
12-
mixins: [componentMixin],
13-
data: function(){
1+
MatestackUiCore.Vue.component('custom<% unless @namespace.nil? %>-<%= @namespace %><% end %>-<%= file_name %>', {
2+
mixins: [MatestackUiCore.componentMixin],
3+
data() {
144
return {
15-
data: {},
16-
errors: {}
17-
}
5+
data: []
6+
};
187
},
198
methods: {},
20-
created: function () {},
21-
beforeDestroy: function() {},
229
mounted: function(){
2310
console.log('Custom Dynamic Component <%= class_name %> mounted!')
2411
}
25-
}
26-
27-
MatestackUiCore.Vue.component('custom-<%= file_name %>', { ... }); //no -cell postfix
28-
let component = Vue.component('<%= file_name %>-cell', componentDef)
29-
30-
export default componentDef
12+
});

lib/generators/matestack_component/templates/matestack_component.rb.erb

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,12 @@
1-
class Components::<% unless @namespace.nil? %><%= @namespace.camelize %>::<% end %><%= class_name %>::Cell::<%= class_name %> < Matestack::Ui::<% if @dynamic == true %>DynamicComponent<% else %>StaticComponent<% end %>
2-
3-
REQUIRED_KEYS = [] # [:symbols]
4-
5-
# use the setup method if dealing with a dynamic component and/or to use custom HAML files
6-
def setup
7-
# access the Vue.JS component_config
8-
# @component_config[:attribute] = attribute
9-
# set up tag_attributes to use in the HAML view
10-
# @tag_attributes.merge!({ "attribute": options[:attribute],
11-
# "href": link_path,
12-
# "@click.prevent": navigate_to(link_path),
13-
# "v-bind:class": "{ active: isActive }",
14-
# "target": options[:target] ||= nil
15-
# })
16-
end
1+
class Components::<% unless @namespace.nil? %><%= @namespace.camelize %>::<% end %><%= class_name %> < Matestack::Ui::<% if @dynamic == true %>DynamicComponent<% else %>StaticComponent<% end %>
172

183
def prepare
194
# DB queries and API calls go here
205
end
216

22-
# use the response method if you only need to orchestrate existing matestack components
237
def response
248
components {
25-
# other matestack components go here
9+
# orchestrate existing matestack components here
2610
}
2711
end
2812

0 commit comments

Comments
 (0)