You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
raisePropertyOverwritingExistingMethodException,"Optional property #{prop} would overwrite already defined instance method for #{self.class}"ifself.respond_to?prop
@@ -40,94 +40,131 @@ See below for an overview of the various possibilities Matestack provides for co
40
40
41
41
By passing options to a component, they get very flexible and can take various input, e.g. *i18n* strings or *instance variables*!
42
42
43
-
#### Passing options as a hash
43
+
#### Define optional and required properties
44
44
45
-
As before, create a component in it's respective file, in this case `app/matestack/components/some/component.rb`:
45
+
Matestack Components give you the option to define required and optional properties for a component. It creates helpers for these properties automatically.
46
+
47
+
##### Required
48
+
49
+
Required properties are required for your component to work, like the name suggests. If at least one required property is missing a `Matestack::Ui::Core::Properties::PropertyMissingException` is raised.
50
+
Declare your required properties by calling `requires` as follows:
plain "I'm a static component and got some option: #{@options[:some_option]} and some other option: #{@options[:some_other][:option]}"
54
-
end
55
-
}
56
-
end
55
+
requires :some_property, :some_other
57
56
58
57
end
59
58
```
60
59
61
-
On the example page, directly pass the options to the static component as shown below:
60
+
You then can use these properties simply by calling the provided helper method, which is generated for you. The helper method name corresponds to the passed property name.
# display some_property plain inside a div and some_other property inside a paragraph beneath it
69
+
div do
70
+
plain some_property
71
+
end
72
+
paragraph text: some_other
76
73
end
77
74
78
75
end
79
76
```
80
77
81
-
The outcome is quite as expected:
78
+
##### Optional
82
79
83
-
```html
84
-
<divid="div-on-page">
85
-
<divid="my-component">
86
-
I'm a static component and got some option: hello! and some other option: world!
87
-
</div>
88
-
</div>
80
+
To define optional attributes you can use the same syntax as `requires`. Just use `optional` instead of `requires`. Optional attributes are optional and not validated for presence like required attributes.
"div > custom_specialComponent > required key 'some_option' is missing"
143
+
<divid="div-on-page">
144
+
<div>
145
+
hello!
146
+
</div>
147
+
<p>world!</p>
148
+
</div>
149
+
```
150
+
151
+
##### Alias properties
152
+
153
+
Matestack tries to prevent overriding existing methods while creating helpers. If you pass a property with a name that matches any instance method of your component matestack will raise a `Matestack::Ui::Core::Properties::PropertyOverwritingExistingMethodException`.
154
+
To use property names that would raise this exception, simply provide an alias name with the `as:` option. You can then use the alias accordingly.
0 commit comments