web_blocks 2.0.0.dev
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 +15 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +23 -0
- data/.travis.yml +8 -0
- data/CHANGELOG.md +1 -0
- data/CONTRIBUTING.md +1 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +27 -0
- data/README.md +641 -0
- data/Rakefile +13 -0
- data/bin/blocks +9 -0
- data/demo/.gitignore +4 -0
- data/demo/Blockfile.rb +67 -0
- data/demo/bower.json +8 -0
- data/demo/package.json +5 -0
- data/demo/src/config/WebBlocks-breakpoints.scss +9 -0
- data/lib/web_blocks/framework.rb +20 -0
- data/lib/web_blocks/manager/bower.rb +106 -0
- data/lib/web_blocks/manager/builder/base.rb +31 -0
- data/lib/web_blocks/manager/builder/js.rb +54 -0
- data/lib/web_blocks/manager/builder/scss.rb +57 -0
- data/lib/web_blocks/manager/parallel_builder.rb +52 -0
- data/lib/web_blocks/product/concat_file/js.rb +15 -0
- data/lib/web_blocks/product/concat_file/raw.rb +33 -0
- data/lib/web_blocks/product/concat_file/scss.rb +21 -0
- data/lib/web_blocks/strategy/compile/scss.rb +90 -0
- data/lib/web_blocks/strategy/link/base.rb +51 -0
- data/lib/web_blocks/strategy/link/js.rb +30 -0
- data/lib/web_blocks/strategy/link/scss.rb +30 -0
- data/lib/web_blocks/structure/attribute/dependency.rb +25 -0
- data/lib/web_blocks/structure/attribute/loose_dependency.rb +25 -0
- data/lib/web_blocks/structure/attribute/reverse_dependency.rb +16 -0
- data/lib/web_blocks/structure/attribute/reverse_loose_dependency.rb +16 -0
- data/lib/web_blocks/structure/block.rb +95 -0
- data/lib/web_blocks/structure/font_file.rb +9 -0
- data/lib/web_blocks/structure/framework.rb +79 -0
- data/lib/web_blocks/structure/img_file.rb +9 -0
- data/lib/web_blocks/structure/js_file.rb +9 -0
- data/lib/web_blocks/structure/raw_file.rb +30 -0
- data/lib/web_blocks/structure/scss_file.rb +9 -0
- data/lib/web_blocks/structure/tree/leaf_node.rb +44 -0
- data/lib/web_blocks/structure/tree/node.rb +14 -0
- data/lib/web_blocks/structure.rb +7 -0
- data/lib/web_blocks/support/attributes/class/container.rb +24 -0
- data/lib/web_blocks/support/attributes/container.rb +41 -0
- data/lib/web_blocks/support/parallel_jobs.rb +26 -0
- data/lib/web_blocks/support/scoped_logger.rb +49 -0
- data/lib/web_blocks/support/tree/child.rb +23 -0
- data/lib/web_blocks/support/tree/node.rb +14 -0
- data/lib/web_blocks/support/tree/parent.rb +35 -0
- data/lib/web_blocks/support/tsort/hash.rb +29 -0
- data/lib/web_blocks/thor/base/class/type_get_class_from_string.rb +36 -0
- data/lib/web_blocks/thor/base/class/types.rb +21 -0
- data/lib/web_blocks/thor/base/initialize.rb +145 -0
- data/lib/web_blocks/thor/base/prepare_blocks.rb +155 -0
- data/lib/web_blocks/thor/base.rb +12 -0
- data/lib/web_blocks/thor/build/all.rb +30 -0
- data/lib/web_blocks/thor/build.rb +13 -0
- data/lib/web_blocks/thor/inspect/blocks/attribute_printer.rb +48 -0
- data/lib/web_blocks/thor/inspect/blocks/block_printer.rb +43 -0
- data/lib/web_blocks/thor/inspect/blocks/printer.rb +24 -0
- data/lib/web_blocks/thor/inspect/blocks.rb +27 -0
- data/lib/web_blocks/thor/inspect/bower_registry.rb +24 -0
- data/lib/web_blocks/thor/inspect/dependency_list.rb +30 -0
- data/lib/web_blocks/thor/inspect/dependency_order.rb +26 -0
- data/lib/web_blocks/thor/inspect.rb +11 -0
- data/lib/web_blocks/thor/partial/compile/scss.rb +24 -0
- data/lib/web_blocks/thor/partial/compile.rb +13 -0
- data/lib/web_blocks/thor/partial/link/js.rb +23 -0
- data/lib/web_blocks/thor/partial/link/scss.rb +23 -0
- data/lib/web_blocks/thor/partial/link.rb +13 -0
- data/lib/web_blocks/thor/partial/runner.rb +14 -0
- data/lib/web_blocks/thor/runner.rb +16 -0
- data/lib/web_blocks/thor/watch/all.rb +67 -0
- data/lib/web_blocks/thor/watch.rb +13 -0
- data/lib/web_blocks/version.rb +3 -0
- data/lib/web_blocks.rb +13 -0
- data/test/init.rb +7 -0
- data/test/web_blocks/framework.rb +40 -0
- data/test/web_blocks/structure.rb +42 -0
- data/test/web_blocks/support/attribute/class/container.rb +29 -0
- data/test/web_blocks/support/attribute/container.rb +71 -0
- data/test/web_blocks/support/tree/child.rb +60 -0
- data/test/web_blocks/support/tree/node.rb +18 -0
- data/test/web_blocks/support/tree/parent.rb +81 -0
- data/test/web_blocks/version.rb +10 -0
- data/web_blocks.gemspec +35 -0
- metadata +297 -0
data/README.md
ADDED
@@ -0,0 +1,641 @@
|
|
1
|
+
# WebBlocks
|
2
|
+
|
3
|
+
WebBlocks is package, configuration and dependency manager for web assets (SCSS, JS, images, and fonts).
|
4
|
+
|
5
|
+
## Status
|
6
|
+
|
7
|
+
[](https://codeclimate.com/github/WebBlocks/WebBlocks) [](https://travis-ci.org/WebBlocks/WebBlocks) [](https://coveralls.io/r/WebBlocks/WebBlocks?branch=master) [](https://gemnasium.com/WebBlocks/WebBlocks)
|
8
|
+
|
9
|
+
This repository contains the code base for WebBlocks 2.0, which is currently **under development** and **not intended for use at this time**. For those interested in using WebBlocks today, please see WebBlocks 1 under the [ucla/WebBlocks](https://github.com/ucla/WebBlocks) repository.
|
10
|
+
|
11
|
+
## License
|
12
|
+
|
13
|
+
WebBlocks is open-source software licensed under the **BSD 3-clause license**. The full text of the license may be found in the [LICENSE](https://github.com/WebBlocks/WebBlocks/blob/master/LICENSE.txt) file.
|
14
|
+
|
15
|
+
## Credits
|
16
|
+
|
17
|
+
WebBlocks is managed by [Eric Bollens](https://github.com/ebollens) as part of a collaboration between the University of California, the Mobile Web Framework community and others.
|
18
|
+
|
19
|
+
WebBlocks is a product of its contributors, including those who have contributed code, submitted bugs or even simply participated in the dialogue.
|
20
|
+
|
21
|
+
WebBlocks is built on top of a number of outstanding open source platforms and packages including [Ruby](http://www.ruby-lang.org/), [RubyGems](http://rubygems.org/) [Bundler](http://gembundler.com/), [Node.js](http://nodejs.org/), [npm](https://npmjs.org/), [Saas](http://sass-lang.com/), [Compass](http://compass-style.org/), [Thor](http://whatisthor.com/), [Rake](http://rake.rubyforge.org/), [File System State Monitor](https://github.com/ttilley/fssm), [sass-css-importer](https://github.com/chriseppstein/sass-css-importer), [ruby-bower](https://github.com/kaeff/ruby-bower), [fork](https://github.com/apeiros/fork) and [extend_method](https://github.com/ebollens/ruby-extend_method). A sincere thanks is extended to the authors of all these fine tools.
|
22
|
+
|
23
|
+
## Installation
|
24
|
+
|
25
|
+
**NOTE** Assuming installation in one of the ways described as follows, this documentation uses `blocks` as a shell command; in cases where it's installed locally by bundle rather than globally, it may be necessary to use `bundle exec blocks` instead.
|
26
|
+
|
27
|
+
### Download
|
28
|
+
|
29
|
+
#### From Source
|
30
|
+
|
31
|
+
Download or clone repository from:
|
32
|
+
|
33
|
+
> https://github.com/WebBlocks/WebBlocks
|
34
|
+
|
35
|
+
Install Ruby dependencies:
|
36
|
+
|
37
|
+
```
|
38
|
+
bundle
|
39
|
+
```
|
40
|
+
|
41
|
+
#### As Gem
|
42
|
+
|
43
|
+
Add the following to `Gemfile` (creating it if it does not exist):
|
44
|
+
|
45
|
+
```
|
46
|
+
gem 'WebBlocks', :git => 'https://github.com/WebBlocks/WebBlocks.git'
|
47
|
+
```
|
48
|
+
|
49
|
+
Install it as a Gemfile dependency:
|
50
|
+
|
51
|
+
```
|
52
|
+
bundle
|
53
|
+
```
|
54
|
+
|
55
|
+
### Bower
|
56
|
+
|
57
|
+
WebBlocks requires Bower to be installed.
|
58
|
+
|
59
|
+
#### Globally
|
60
|
+
|
61
|
+
The easiest way to do this:
|
62
|
+
|
63
|
+
```
|
64
|
+
npm install -g bower
|
65
|
+
```
|
66
|
+
|
67
|
+
Additionally, you must ensure that your rc file (`.bashrc`, `.zshrc`, etc.) properly sets `$NODE_PATH` to the `node_modules` directory where global installs are placed. If it does not, you may want to add something of the form:
|
68
|
+
|
69
|
+
```
|
70
|
+
export NODE_PATH=$(npm config get prefix)/lib/node_modules
|
71
|
+
```
|
72
|
+
|
73
|
+
#### Locally
|
74
|
+
|
75
|
+
An alternative is that, in the directory where you're going to compile WebBlocks (the same as where `bower.json` will be placed), you may do a local install of bower:
|
76
|
+
|
77
|
+
```
|
78
|
+
npm install bower
|
79
|
+
```
|
80
|
+
|
81
|
+
Alternatively, this can be done by defining a `package.json`:
|
82
|
+
|
83
|
+
```json
|
84
|
+
{
|
85
|
+
"dependencies": {
|
86
|
+
"bower":">=1.2.8"
|
87
|
+
}
|
88
|
+
}
|
89
|
+
```
|
90
|
+
|
91
|
+
And then simply calling:
|
92
|
+
|
93
|
+
```
|
94
|
+
npm install
|
95
|
+
```
|
96
|
+
|
97
|
+
## Usage
|
98
|
+
|
99
|
+
WebBlocks provides a `blocks` executable that wraps several commands. These commands include:
|
100
|
+
|
101
|
+
* `inspect`, which analyzes a WebBlocks configuration;
|
102
|
+
* `build`, which produces a WebBlocks build;
|
103
|
+
* `watch`, which will reproduce a WebBlocks build every time a source file changes;
|
104
|
+
* `partial`, which allows one to run only one step in the build process.
|
105
|
+
|
106
|
+
Each of these have one or more actions below them, except partial, which actually has sub-commands below it, each with their own actions.
|
107
|
+
|
108
|
+
### Getting Help
|
109
|
+
|
110
|
+
To see a list of all commands:
|
111
|
+
|
112
|
+
```
|
113
|
+
$ blocks help
|
114
|
+
```
|
115
|
+
|
116
|
+
To get information about a particular command:
|
117
|
+
|
118
|
+
```
|
119
|
+
$ blocks [command [subcommand]] help [action]
|
120
|
+
```
|
121
|
+
|
122
|
+
For just a command:
|
123
|
+
|
124
|
+
```
|
125
|
+
$ blocks build help
|
126
|
+
```
|
127
|
+
|
128
|
+
For a command and action:
|
129
|
+
|
130
|
+
```
|
131
|
+
$ blocks inspect help dependency_list
|
132
|
+
```
|
133
|
+
|
134
|
+
For a command, sub-command and action:
|
135
|
+
|
136
|
+
```
|
137
|
+
$ blocks partial compile help scss
|
138
|
+
```
|
139
|
+
|
140
|
+
### Global Options
|
141
|
+
|
142
|
+
All commands (except `help`) accept several global options:
|
143
|
+
|
144
|
+
* `--base-path` defines an explicit directory where `bower.json` resides (and where `bower_components`, `.blocks` and `build` will be created). If this is not specified, WebBlocks will attempt to use the current working directory, or if there's no `bower.json` file in there, it will traverse into parent directories searching for one, exiting with a failure if neither the current working directory nor any parent contains a `bower.json` file.
|
145
|
+
* `--blockfile-path` defines an explicit Blockfile location relative to the current working directory. If this is not specified, then `Blockfile.rb` is assumed to reside in the `--base-path`.
|
146
|
+
* `--include` defines one or more blocks to include that aren't included by the blockfile itself. Route segments should be space-delimited, and includes should be comma-delimited: `--include efx driver tabs, efx driver toggle`. If spaces or special characters are used, then the values must be enclosed in quotes or escaped.
|
147
|
+
* `--reload-bower` to discard the components in `bower_components` and fetch a fresh copy. This option should be used whenever dependencies are modified in `bower.json`.
|
148
|
+
* `--reload-registry` to discard the bower registry cache and use a fresh copy. This option should be used if `node_modules/bower/bin/bower` is ever explicitly called.
|
149
|
+
|
150
|
+
### Build
|
151
|
+
|
152
|
+
This command will link, compile and produce a build into the `build` directory:
|
153
|
+
|
154
|
+
```
|
155
|
+
blocks build
|
156
|
+
```
|
157
|
+
|
158
|
+
### Watch
|
159
|
+
|
160
|
+
This command will watch for pertinent changes and rebuild into the `build` directory:
|
161
|
+
|
162
|
+
```
|
163
|
+
blocks watch
|
164
|
+
```
|
165
|
+
|
166
|
+
### Development
|
167
|
+
|
168
|
+
#### Testing
|
169
|
+
|
170
|
+
Tests may be performed through `rake`:
|
171
|
+
|
172
|
+
```
|
173
|
+
rake test
|
174
|
+
```
|
175
|
+
|
176
|
+
**NOTE** WebBlocks currently only has partial test coverage. Work is ongoing to provide full coverage.
|
177
|
+
|
178
|
+
#### Partial Builds
|
179
|
+
|
180
|
+
The build process is composed of several separate steps. These should not usually be called on their own, except for testing, debugging or advanced use cases. Their outputs may be found under `.blocks/workspace`.
|
181
|
+
|
182
|
+
##### Link
|
183
|
+
|
184
|
+
An SCSS file composed of `@import` rules may be generated into the temporary workspace:
|
185
|
+
|
186
|
+
```
|
187
|
+
blocks partial link scss
|
188
|
+
```
|
189
|
+
|
190
|
+
A JS file of all JS sources concatenated together may be generated into the temporary workspace:
|
191
|
+
|
192
|
+
```
|
193
|
+
blocks partial link js
|
194
|
+
```
|
195
|
+
|
196
|
+
##### Compile
|
197
|
+
|
198
|
+
The link phase is all that's needed to compose the WebBlocks Javascript; however, for SCSS, only an import sheet is generated, and thus an actual CSS file may be generated into the temporary workspace:
|
199
|
+
|
200
|
+
```
|
201
|
+
blocks partial compile scss
|
202
|
+
```
|
203
|
+
|
204
|
+
#### Inspect
|
205
|
+
|
206
|
+
This command is used to inspect WebBlocks configuration.
|
207
|
+
|
208
|
+
##### Bower
|
209
|
+
|
210
|
+
To get a list of components to be registered based on `bower.json`:
|
211
|
+
|
212
|
+
```
|
213
|
+
blocks inspect bower_registry
|
214
|
+
```
|
215
|
+
|
216
|
+
##### Blocks
|
217
|
+
|
218
|
+
To get a list of blocks and files as defined by `Blockfile.rb`:
|
219
|
+
|
220
|
+
```
|
221
|
+
blocks inspect blocks
|
222
|
+
```
|
223
|
+
|
224
|
+
To include attributes set on blocks and files:
|
225
|
+
|
226
|
+
```
|
227
|
+
blocks inspect blocks --attributes
|
228
|
+
```
|
229
|
+
|
230
|
+
To filter within a route:
|
231
|
+
|
232
|
+
```
|
233
|
+
blocks inspect blocks --route="WebBlocks-visibility"
|
234
|
+
```
|
235
|
+
|
236
|
+
**NOTE** Attributes here are raw as defined by the `Blocksfile.rb` file and the `Blockfile.rb` files of registered blocks; some files with `:required = false` attributes here may still be included during the link phase on account of dependency resolution. When looking at what will be required, the dependency inspection actions should be used instead.
|
237
|
+
|
238
|
+
##### Dependencies
|
239
|
+
|
240
|
+
To get a list of dependencies per the configuration of `Blocksfile.rb` and the blocks themselves:
|
241
|
+
|
242
|
+
```
|
243
|
+
blocks inspect dependency_list
|
244
|
+
```
|
245
|
+
|
246
|
+
To get an list of files in the order that they will be compiled by WebBlocks:
|
247
|
+
|
248
|
+
```
|
249
|
+
blocks inspect dependency_order
|
250
|
+
```
|
251
|
+
|
252
|
+
Both commands support a type option for the file type.
|
253
|
+
|
254
|
+
For example, to see only `scss` files:
|
255
|
+
|
256
|
+
```
|
257
|
+
blocks inspect dependency_order --type=scss
|
258
|
+
```
|
259
|
+
|
260
|
+
## Getting Started
|
261
|
+
|
262
|
+
### Defining Components
|
263
|
+
|
264
|
+
Blocks are the fundamental constituents of WebBlocks, defined as bower components. Consequently, `bower.json` must define and name and version for the build you're going to create. The name is important in that it defines the block that WebBlocks will load by default when compiling (although others may be included as dependencies or explicitly - more on this later):
|
265
|
+
|
266
|
+
```json
|
267
|
+
{
|
268
|
+
"name": "my-app",
|
269
|
+
"version": "1.0.0"
|
270
|
+
}
|
271
|
+
```
|
272
|
+
|
273
|
+
Further, in this example, suppose the goal is to use the `WebBlocks-visibility` block. This block resides in the Git repository [WebBlocks/block-visibility](`https://github.com/WebBlocks/block-visibility`), and thus it may be included by adding it to the `dependencies` section of `bower.json`:
|
274
|
+
|
275
|
+
```json
|
276
|
+
{
|
277
|
+
"name": "my-app",
|
278
|
+
"version": "1.0.0",
|
279
|
+
"dependencies": {
|
280
|
+
"WebBlocks-visibility": "WebBlocks/block-visibility"
|
281
|
+
}
|
282
|
+
}
|
283
|
+
```
|
284
|
+
|
285
|
+
### Including a Block
|
286
|
+
|
287
|
+
While packages define blocks to include, generally they will not be included unless specified explicitly.
|
288
|
+
|
289
|
+
To include all of `WebBlocks-visibility`, create `Blockfile.rb` with the following:
|
290
|
+
|
291
|
+
```ruby
|
292
|
+
include 'WebBlocks-visibility'
|
293
|
+
```
|
294
|
+
|
295
|
+
This resolves out for compilation as:
|
296
|
+
|
297
|
+
```
|
298
|
+
$ blocks inspect dependency_order
|
299
|
+
/Users/ebollens/Sites/test/bower_components/WebBlocks-visibility/src/_hide.scss
|
300
|
+
/Users/ebollens/Sites/test/bower_components/WebBlocks-visibility/src/accessible/_hide.scss
|
301
|
+
/Users/ebollens/Sites/test/bower_components/WebBlocks-breakpoints/_variables.scss
|
302
|
+
/Users/ebollens/Sites/test/bower_components/WebBlocks-visibility/src/breakpoint/_hide.scss
|
303
|
+
/Users/ebollens/Sites/test/bower_components/WebBlocks-visibility/src/breakpoint/_hide-above.scss
|
304
|
+
/Users/ebollens/Sites/test/bower_components/WebBlocks-visibility/src/media-query/_hide.scss
|
305
|
+
```
|
306
|
+
|
307
|
+
WebBlocks has linked all WebBlocks-visibility constituents, as well as its requites - namely WebBlocks-breakpoint (which we did not specify but was rather specified in the WebBlocks-visibility [Blockfile.rb](https://github.com/WebBlocks/block-visibility/blob/master/Blockfile.rb) and [bower.json](https://github.com/WebBlocks/block-visibility/blob/master/bower.json) files).
|
308
|
+
|
309
|
+
You can build it as:
|
310
|
+
|
311
|
+
```
|
312
|
+
$ blocks build
|
313
|
+
```
|
314
|
+
|
315
|
+
Alternatively, you can perform this same operation *without* a `Blockfile.rb` defined in your workspace through the use of a command-line argument:
|
316
|
+
|
317
|
+
```
|
318
|
+
$ blocks build --include WebBlocks-visibility
|
319
|
+
```
|
320
|
+
|
321
|
+
**NOTE:** Using the `--include` flag when the base directory (where `bower.json` resides) contains a `Blockfile.rb` will lead to all inclusions occurring both that are triggered by `Blocksfile.rb` and by `--include`. To skip using a Blockfile, simply add `--blockfile-path FALSE`.
|
322
|
+
|
323
|
+
### Including Specific Sub-Blocks
|
324
|
+
|
325
|
+
WebBlocks allows one to include sub-blocks rather than just full blocks.
|
326
|
+
|
327
|
+
Based on the configuration above, let's inspect the available blocks:
|
328
|
+
|
329
|
+
```
|
330
|
+
$ blocks inspect blocks
|
331
|
+
framework (Framework)
|
332
|
+
WebBlocks-visibility (Block)
|
333
|
+
hide (Block)
|
334
|
+
_hide.scss (ScssFile)
|
335
|
+
accessible (Block)
|
336
|
+
hide (Block)
|
337
|
+
_hide.scss (ScssFile)
|
338
|
+
breakpoint (Block)
|
339
|
+
hide (Block)
|
340
|
+
_hide.scss (ScssFile)
|
341
|
+
hide-above (Block)
|
342
|
+
_hide-above.scss (ScssFile)
|
343
|
+
media-query (Block)
|
344
|
+
hide (Block)
|
345
|
+
_hide.scss (ScssFile)
|
346
|
+
WebBlocks-breakpoints (Block)
|
347
|
+
_variables.scss (ScssFile)
|
348
|
+
```
|
349
|
+
|
350
|
+
Anything designated as a block may be specified as an `include`. Returning the `Blockfile.rb`, one could tighten the block inclusion scope be replacing its current content with something like:
|
351
|
+
|
352
|
+
```ruby
|
353
|
+
include 'WebBlocks-visibility', 'accessible'
|
354
|
+
include 'WebBlocks-visibility', 'breakpoint'
|
355
|
+
```
|
356
|
+
|
357
|
+
This has tightened up the inclusions accordingly:
|
358
|
+
|
359
|
+
```ruby
|
360
|
+
$ blocks inspect dependency_order
|
361
|
+
/Users/ebollens/Sites/test/bower_components/WebBlocks-visibility/src/accessible/_hide.scss
|
362
|
+
/Users/ebollens/Sites/test/bower_components/WebBlocks-breakpoints/_variables.scss
|
363
|
+
/Users/ebollens/Sites/test/bower_components/WebBlocks-visibility/src/breakpoint/_hide.scss
|
364
|
+
/Users/ebollens/Sites/test/bower_components/WebBlocks-visibility/src/breakpoint/_hide-above.scss
|
365
|
+
```
|
366
|
+
|
367
|
+
Again, build it as:
|
368
|
+
|
369
|
+
```
|
370
|
+
blocks build
|
371
|
+
```
|
372
|
+
|
373
|
+
Alternatively, without multiple scoped includes may be specified as:
|
374
|
+
|
375
|
+
```
|
376
|
+
$ blocks build --include WebBlocks-visibility accessible, WebBlocks-visibility breakpoint
|
377
|
+
```
|
378
|
+
|
379
|
+
### Adding App-specific Sources
|
380
|
+
|
381
|
+
In this example, our `bower.json` file reads:
|
382
|
+
|
383
|
+
```json
|
384
|
+
{
|
385
|
+
"name": "my-app",
|
386
|
+
"version": "1.0.0",
|
387
|
+
"dependencies": {
|
388
|
+
"WebBlocks-visibility": "WebBlocks/block-visibility"
|
389
|
+
}
|
390
|
+
}
|
391
|
+
```
|
392
|
+
|
393
|
+
For the purpose of this example, suppose we have two files:
|
394
|
+
|
395
|
+
* `src/app.js`
|
396
|
+
* `src/styles.scss`
|
397
|
+
|
398
|
+
These can be added to the `Blockfile.rb` as follows:
|
399
|
+
|
400
|
+
```ruby
|
401
|
+
include 'WebBlocks-visibility', 'accessible'
|
402
|
+
include 'WebBlocks-visibility', 'breakpoint'
|
403
|
+
|
404
|
+
block 'my-app' do
|
405
|
+
|
406
|
+
set :path, 'src'
|
407
|
+
|
408
|
+
js_file 'app.js'
|
409
|
+
scss_file 'styles.scss'
|
410
|
+
|
411
|
+
end
|
412
|
+
```
|
413
|
+
|
414
|
+
The items under `my-app` will automatically be included because it has the same name as specified under `bower.json`. This behavior means that, if this were to be included in another project with another name, then it would not be automatically included but rather have to be included like WebBlocks-visibility in this example.
|
415
|
+
|
416
|
+
When developing an application, calling `build` can be repetitive. The `watch` command gets rid of this repetition:
|
417
|
+
|
418
|
+
```
|
419
|
+
blocks watch
|
420
|
+
```
|
421
|
+
|
422
|
+
Any time that a bower component, blockfile or source file changes, it will rebuild the necessary components.
|
423
|
+
|
424
|
+
### Using Depedencies to Control Load Order
|
425
|
+
|
426
|
+
The WebBlocks-breakpoints module provides a set of variables that it will define unless they're already defined. This enables WebBlocks-visibility's breakpoint-based classes. Suppose, however, that we wish to inject our own variables.
|
427
|
+
|
428
|
+
To start things off, create `src/config/WebBlocks-breakpoint.scss` such as:
|
429
|
+
|
430
|
+
```css
|
431
|
+
$breakpoint-xxsmall: 360px !default;
|
432
|
+
$breakpoint-xsmall: 480px !default;
|
433
|
+
$breakpoint-small: 640px !default;
|
434
|
+
$breakpoint-medium-small: 768px !default;
|
435
|
+
$breakpoint-medium: 900px !default;
|
436
|
+
$breakpoint-medium-large: 1024px !default;
|
437
|
+
$breakpoint-large: 1200px !default;
|
438
|
+
$breakpoint-xlarge: 1500px !default;
|
439
|
+
$breakpoint-xxlarge: 1800px !default;
|
440
|
+
```
|
441
|
+
|
442
|
+
**NOTE** You should always use `!default` when setting variables, so as to play nice with others who may want to explicitly define these variables earlier in the stack than your block.
|
443
|
+
|
444
|
+
Next, let's define `Blockfile.rb` as follows, including this sub-block but dropping the includes from earlier examples:
|
445
|
+
|
446
|
+
```ruby
|
447
|
+
block 'my-app', :path => 'src' do
|
448
|
+
|
449
|
+
js_file 'app.js'
|
450
|
+
scss_file 'styles.scss'
|
451
|
+
|
452
|
+
block 'config', :path => 'config' do
|
453
|
+
|
454
|
+
block 'WebBlocks-visibility' do
|
455
|
+
|
456
|
+
scss_file 'WebBlocks-breakpoints.scss'
|
457
|
+
reverse_dependency framework.route 'WebBlocks-breakpoints'
|
458
|
+
|
459
|
+
end
|
460
|
+
|
461
|
+
end
|
462
|
+
|
463
|
+
end
|
464
|
+
```
|
465
|
+
|
466
|
+
If we inspect this without any includes, the custom variables file has not been tacked on:
|
467
|
+
|
468
|
+
```
|
469
|
+
$ blocks inspect dependency_order
|
470
|
+
/Users/ebollens/Sites/test/src/app.js
|
471
|
+
/Users/ebollens/Sites/test/src/styles.scss
|
472
|
+
```
|
473
|
+
|
474
|
+
However, if we include something that requires the including of `WebBlocks-breakpoints`, which has a dependency on our config file, our config file will get included before it:
|
475
|
+
|
476
|
+
```
|
477
|
+
$ blocks inspect dependency_order --include WebBlocks-visibility breakpoint
|
478
|
+
/Users/ebollens/Sites/test/src/config/WebBlocks-breakpoints.scss
|
479
|
+
/Users/ebollens/Sites/test/bower_components/WebBlocks-breakpoints/_variables.scss
|
480
|
+
/Users/ebollens/Sites/test/bower_components/WebBlocks-visibility/src/breakpoint/_hide.scss
|
481
|
+
/Users/ebollens/Sites/test/bower_components/WebBlocks-visibility/src/breakpoint/_hide-above.scss
|
482
|
+
/Users/ebollens/Sites/test/src/app.js
|
483
|
+
/Users/ebollens/Sites/test/src/styles.scss
|
484
|
+
```
|
485
|
+
|
486
|
+
### Working with a Existing Block
|
487
|
+
|
488
|
+
Suppose that now we decide to scrap our work with WebBlocks-visibility and instead add the [Efx](https://github.com/ebollens/efx) library to our project:
|
489
|
+
|
490
|
+
```json
|
491
|
+
{
|
492
|
+
"name": "my-app",
|
493
|
+
"version": "1.0.0",
|
494
|
+
"dependencies": {
|
495
|
+
"efx": "ebollens/efx"
|
496
|
+
}
|
497
|
+
}
|
498
|
+
```
|
499
|
+
|
500
|
+
Additionally, we delete `Blockfile.rb`.
|
501
|
+
|
502
|
+
The blocks builder caches packages and metadata, so the first thing we need to do is reload it with the `--reload-bower` flag on any command. In this case, let's inspect the bower components with the reload:
|
503
|
+
|
504
|
+
```
|
505
|
+
$ blocks inspect bower_registry --reload-bower
|
506
|
+
efx
|
507
|
+
/Users/ebollens/Sites/test/bower_components/efx
|
508
|
+
jquery
|
509
|
+
/Users/ebollens/Sites/test/bower_components/jquery
|
510
|
+
```
|
511
|
+
|
512
|
+
Following this, when we call `blocks build`, we end up with empty files. If we use `blocks inspect dependency_list`, it returns an empty set. We need to explicitly choose what we wish to support:
|
513
|
+
|
514
|
+
```
|
515
|
+
$ blocks inspect blocks --attributes
|
516
|
+
framework (Framework)
|
517
|
+
:required = true
|
518
|
+
efx (Block)
|
519
|
+
:required = false
|
520
|
+
:path = "src"
|
521
|
+
engine (Block)
|
522
|
+
:required = true
|
523
|
+
engine.js (JsFile)
|
524
|
+
:required = true
|
525
|
+
driver (Block)
|
526
|
+
:dependencies = [["efx", "engine"]]
|
527
|
+
:required = false
|
528
|
+
:path = "driver"
|
529
|
+
accordion (Block)
|
530
|
+
:required = false
|
531
|
+
accordion.css (ScssFile)
|
532
|
+
:required = true
|
533
|
+
accordion.js (JsFile)
|
534
|
+
:required = true
|
535
|
+
tabs (Block)
|
536
|
+
:required = false
|
537
|
+
tabs.css (ScssFile)
|
538
|
+
:required = true
|
539
|
+
tabs.js (JsFile)
|
540
|
+
:required = true
|
541
|
+
toggle (Block)
|
542
|
+
:required = false
|
543
|
+
toggle.css (ScssFile)
|
544
|
+
:required = true
|
545
|
+
toggle.js (JsFile)
|
546
|
+
:required = true
|
547
|
+
```
|
548
|
+
|
549
|
+
If we wanted to include everything:
|
550
|
+
|
551
|
+
```
|
552
|
+
$ blocks build --include efx
|
553
|
+
```
|
554
|
+
|
555
|
+
If we wanted only to include the Efx engine:
|
556
|
+
|
557
|
+
```
|
558
|
+
$ blocks build --include efx engine
|
559
|
+
```
|
560
|
+
|
561
|
+
Let's settle with taking two of its drivers, tabs and toggle:
|
562
|
+
|
563
|
+
```
|
564
|
+
$ blocks build --include efx driver tabs, efx driver toggle
|
565
|
+
```
|
566
|
+
|
567
|
+
Instead of using the command-line, add this as the contents of `Blockfile.rb`:
|
568
|
+
|
569
|
+
```ruby
|
570
|
+
include 'efx', 'driver', 'tabs'
|
571
|
+
include 'efx', 'driver', 'toggle'
|
572
|
+
```
|
573
|
+
|
574
|
+
An `inspect dependency_order` shows us that, in addition to the drivers, the engine will also be included, given that it's a dependency:
|
575
|
+
|
576
|
+
```
|
577
|
+
$ blocks inspect dependency_order
|
578
|
+
/Users/ebollens/Sites/test/bower_components/efx/src/engine.js
|
579
|
+
/Users/ebollens/Sites/test/bower_components/efx/src/driver/tabs.css
|
580
|
+
/Users/ebollens/Sites/test/bower_components/efx/src/driver/tabs.js
|
581
|
+
/Users/ebollens/Sites/test/bower_components/efx/src/driver/toggle.css
|
582
|
+
/Users/ebollens/Sites/test/bower_components/efx/src/driver/toggle.js
|
583
|
+
```
|
584
|
+
|
585
|
+
### Modifying a Existing Block
|
586
|
+
|
587
|
+
The WebBlocks DSL allows one to re-open an existing block.
|
588
|
+
|
589
|
+
In the case of the [Efx](https://github.com/ebollens/efx) library, the author did not want to impose jQuery as part of the block's build process, in case the user is included it elsewhere; however, in the case of our particular app, we may want to bundle the two together.
|
590
|
+
|
591
|
+
Looking at our registry, we see that, although jQuery is not being included as part of the actual build, it is defined as a bower dependency:
|
592
|
+
|
593
|
+
```
|
594
|
+
$ blocks inspect bower_registry
|
595
|
+
efx
|
596
|
+
/Users/ebollens/Sites/test/bower_components/efx
|
597
|
+
jquery
|
598
|
+
/Users/ebollens/Sites/test/bower_components/jquery
|
599
|
+
```
|
600
|
+
|
601
|
+
Since jQuery doesn't have a `Blockfile.rb` in it's repository, we'll start by adding that definition to `Blockfile.rb`:
|
602
|
+
|
603
|
+
```ruby
|
604
|
+
include 'efx', 'driver', 'tabs'
|
605
|
+
include 'efx', 'driver', 'toggle'
|
606
|
+
|
607
|
+
block 'jquery', :path => 'bower_components/jquery/dist' do
|
608
|
+
js_file 'jquery.js'
|
609
|
+
end
|
610
|
+
```
|
611
|
+
|
612
|
+
Next, also within `Blockfile.rb`, we'll open the `efx` block and add the dependency:
|
613
|
+
|
614
|
+
```ruby
|
615
|
+
include 'efx', 'driver', 'tabs'
|
616
|
+
include 'efx', 'driver', 'toggle'
|
617
|
+
|
618
|
+
block 'jquery', :path => 'bower_components/jquery/dist' do
|
619
|
+
js_file 'jquery.js'
|
620
|
+
end
|
621
|
+
|
622
|
+
block 'efx' do
|
623
|
+
dependency framework.route 'jquery'
|
624
|
+
end
|
625
|
+
```
|
626
|
+
|
627
|
+
Inspecting shows this has the intended effect:
|
628
|
+
|
629
|
+
```
|
630
|
+
$ blocks inspect dependency_order
|
631
|
+
/Users/ebollens/Sites/test/bower_components/jquery/dist/jquery.js
|
632
|
+
/Users/ebollens/Sites/test/bower_components/efx/src/engine.js
|
633
|
+
/Users/ebollens/Sites/test/bower_components/efx/src/driver/tabs.css
|
634
|
+
/Users/ebollens/Sites/test/bower_components/efx/src/driver/tabs.js
|
635
|
+
/Users/ebollens/Sites/test/bower_components/efx/src/driver/toggle.css
|
636
|
+
/Users/ebollens/Sites/test/bower_components/efx/src/driver/toggle.js
|
637
|
+
```
|
638
|
+
|
639
|
+
### Learn More
|
640
|
+
|
641
|
+
See the `demo` folder for a example setup.
|
data/Rakefile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
require 'bundler/gem_tasks'
|
6
|
+
require 'rake'
|
7
|
+
require 'rake/testtask'
|
8
|
+
|
9
|
+
Bundler.setup(:default)
|
10
|
+
|
11
|
+
Rake::TestTask.new do |t|
|
12
|
+
t.test_files = FileList['test/init.rb', 'test/**/*.rb']
|
13
|
+
end
|
data/bin/blocks
ADDED
data/demo/.gitignore
ADDED