File tree Expand file tree Collapse file tree 4 files changed +30
-5
lines changed
lib/generators/matestack/component
templates/app/matestack/components/%namespace%
spec/lib/generators/matestack/component Expand file tree Collapse file tree 4 files changed +30
-5
lines changed Original file line number Diff line number Diff line change @@ -12,9 +12,11 @@ def namespace
12
12
options [ :namespace ]
13
13
end
14
14
15
- def create_component
16
- @dynamic = options [ :dynamic ]
15
+ def dynamic
16
+ options [ :dynamic ]
17
+ end
17
18
19
+ def create_component
18
20
# Future: Check for matestack-compatible namespacing!
19
21
20
22
template 'app/matestack/components/%namespace%/%file_name%.rb.tt'
Original file line number Diff line number Diff line change 1
1
// Require your custom component in your application.js before usage
2
2
// Place it below "//= require matestack-ui-core" using the following line:
3
- //= require <% unless @ namespace.nil? %><%= @ namespace %>/<% end %><%= file_name %>
3
+ //= require <% unless namespace.nil? %><%= namespace %>/<% end %><%= file_name %>
4
4
5
- MatestackUiCore.Vue.component('custom<% unless @ namespace.nil? %>-<%= @ namespace %><% end %>-<%= file_name %>', {
5
+ MatestackUiCore.Vue.component('custom<% unless namespace.nil? %>-<%= namespace %><% end %>-<%= file_name %>', {
6
6
mixins: [MatestackUiCore.componentMixin],
7
7
data: function() {
8
8
return {
Original file line number Diff line number Diff line change 1
- class Components::<% unless @ namespace.nil? %><%= @ namespace.camelize %>::<% end %><%= class_name %> < Matestack::Ui::<% if @ dynamic == true %>DynamicComponent<% else %>StaticComponent<% end %>
1
+ class Components::<% unless namespace.nil? %><%= namespace.camelize %>::<% end %><%= class_name %> < Matestack::Ui::<% if dynamic == true %>DynamicComponent<% else %>StaticComponent<% end %>
2
2
def prepare
3
3
# DB queries and API calls go here
4
4
end
Original file line number Diff line number Diff line change 30
30
assert_file "app/matestack/components/example_component.js" , /custom-example_component\b /
31
31
end
32
32
33
+ it "creates a haml file with the haml option" do
34
+ run_generator %w( example_component --haml )
35
+
36
+ assert_file "app/matestack/components/example_component.haml" , %r{.example_component{@tag_attributes}}
37
+ assert_file "app/matestack/components/example_component.haml" , /This is your custom ExampleComponent component/
38
+ end
39
+
40
+ it "creates a scss file with the scss option" do
41
+ run_generator %w( example_component --scss )
42
+
43
+ assert_file "app/matestack/components/example_component.scss" , %r{// your styles for the component ExampleComponent go here}
44
+ end
45
+
46
+ it "creates a custom component in the right namespace" do
47
+ run_generator %w( example_component --namespace example_namespace --dynamic --scss --haml )
48
+
49
+ assert_file "app/matestack/components/example_namespace/example_component.rb" , /class Components::ExampleNamespace::ExampleComponent < Matestack::Ui::DynamicComponent/
50
+ assert_file "app/matestack/components/example_namespace/example_component.js" , /custom-example_namespace-example_component/
51
+ assert_file "app/matestack/components/example_namespace/example_component.js" , %r{require example_namespace/example_component}
52
+ assert_file "app/matestack/components/example_namespace/example_component.haml"
53
+ assert_file "app/matestack/components/example_namespace/example_component.scss"
54
+ end
55
+
33
56
end
You can’t perform that action at this time.
0 commit comments