Skip to content

Commit adbb22b

Browse files
committed
webpack: adding documentation
#343
1 parent a492352 commit adbb22b

File tree

2 files changed

+68
-12
lines changed

2 files changed

+68
-12
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,12 @@ We love to see more and more people using and contributing to matestack-ui-core.
2727
* core refactoring, increased core maintainability and code quality
2828
* better integration in existing rails apps
2929
* improved documentation
30-
* webpacker support and npm based js dependecy management
3130
* improved dynamic core components (especially form components)
3231

3332

3433
### Installation:
3534

36-
Click here to see how you can add Matestack UI to your existing Rails application: [Installation Guide](https://www.matestack.org/docs/install)
35+
Click here to see how you can add Matestack UI to your existing Rails application: [Installation Guide](./docs/install)
3736

3837
### Features:
3938

docs/install/README.md

Lines changed: 67 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Install
22

3-
If your're using the classic Rails assets pipeline, this guide shows you how to
4-
add matestack to your Rails app.
3+
This guide shows you how to add matestack-ui-core to an existing rails application.
54

65
## Gemfile
76

@@ -19,15 +18,56 @@ $ bundle install
1918

2019
## Javascript
2120

22-
Require 'matestack-ui-core' in your `assets/javascript/application.js`
21+
Matestack uses javascripts and, in particular, [vuejs](http://vuejs.org). To include these into your existing rails app, matestack supports both, [webpack](https://webpack.js.org/)([er](https://github.com/rails/webpacker/)) and the [asset pipeline](https://guides.rubyonrails.org/asset_pipeline.html).
22+
23+
Rails 6+ apps, by default, use webpacker, rails 5 apps, by default, use the asset pipeline.
24+
25+
### Webpacker
26+
27+
Add 'matestack-ui-core' to your `package.json` by running:
28+
29+
```
30+
$ yarn add https://github.com/matestack/matestack-ui-core#v0.7.4
31+
$ yarn install
32+
```
33+
34+
This adds the npm package that provides the javascript files corresponding to matestack-ui-core ruby gem. Make sure that the npm package version matches the gem version. To find out what gem version you are using, you may use `bundle info matestack-ui-core`.
35+
36+
Next, import 'matestack-ui-core' in your `app/javascript/packs/application.js`
37+
38+
```js
39+
import MatestackUiCore from 'matestack-ui-core'
40+
```
41+
42+
and compile the javascript code with webpack:
43+
44+
```
45+
$ bin/webpack
46+
```
47+
48+
When, in the future, you update the matestack-ui-core gem, make also sure to update the npm package as well.
49+
50+
### Asset Pipeline
51+
52+
If you are not using webpacker but the asset pipeline, you don't need to install a separate npm package. All required javascript libraries including vuejs are provided by matestack-ui-core ready-to-use via the asset pipeline.
53+
54+
Require 'matestack-ui-core' in your `app/assets/javascript/application.js`
2355

2456
```javascript
2557
//= require matestack-ui-core
2658
```
27-
Note:
2859

29-
- **Remove turbolinks! Currently, matestack can't be used with turbolinks. This will be fixed soon**
30-
- Additional Webpacker integration is coming soon
60+
Require 'matestack-ui-core' in your `app/assets/stylesheets/application.css`
61+
62+
```css
63+
/*
64+
*= require matestack-ui-core
65+
*/
66+
```
67+
68+
### Turbolinks Coming Soon
69+
70+
At the moment, matestack-ui-core is not compatible with [turbolinks](https://github.com/turbolinks/turbolinks). Please remove or deactive turbolinks for now. We are working on turbolinks support and will add it soon. ([Issue #232](https://github.com/matestack/matestack-ui-core/issues/232))
3171

3272
## Matestack Folder
3373

@@ -54,7 +94,7 @@ You need to add the ID "matestack_ui" to some part of your application layout (o
5494

5595
For Example, your `app/views/layouts/application.html.erb` should look like this:
5696

57-
```html+erb
97+
```erb
5898
<!DOCTYPE html>
5999
<html>
60100
<head>
@@ -63,6 +103,11 @@ For Example, your `app/views/layouts/application.html.erb` should look like this
63103
<%= csp_meta_tag %>
64104
65105
<%= stylesheet_link_tag 'application', media: 'all' %>
106+
107+
<!-- if you are using webpacker: -->
108+
<%= javascript_pack_tag 'application' %>
109+
110+
<!-- if you are using the asset pipeline: -->
66111
<%= javascript_include_tag 'application' %>
67112
</head>
68113
@@ -75,13 +120,25 @@ For Example, your `app/views/layouts/application.html.erb` should look like this
75120
```
76121
Don't apply the matestack_ui ID to the body tag.
77122

78-
## Extend Asset Paths
123+
## Adding Support for Custom Components
124+
125+
If you intend to write custom dynamic matestack components for your app, you need to make those accessible to the matestack-ui-core javscript code.
126+
127+
### Webpack
128+
129+
When using webpack, make sure to import your custom components in `app/javascript/packs/application.js`:
130+
131+
```js
132+
import MatestackUiCore from 'matestack-ui-core'
133+
import '../../../app/matestack/components/my_custom_component'
134+
```
79135

80-
In order to enable custom Vue.js components, add the matestack folder to the asset paths:
136+
### Asset Pipeline
81137

82-
`config/initializers/assets.rb`
138+
When using the asset pipeline, add the matestack folder to the asset paths:
83139

84140
```ruby
141+
# config/initializers/assets.rb
85142
Rails.application.config.assets.paths << Rails.root.join('app/matestack/components')
86143
```
87144

0 commit comments

Comments
 (0)