Skip to content
Permalink
Browse files

Merge branch 'release-060' into build

  • Loading branch information...
jodosha committed Jan 12, 2016
2 parents f743ee4 + 9686a24 commit b3996b753563e200dd64638127a4690ad59732de
@@ -168,7 +168,7 @@ def encode_text(text)
end

def lotus_version
'0.5.0'
'0.6.0'
end
end

@@ -81,7 +81,7 @@ We strongly suggest to use [EcmaScript 6](http://es6-features.org/) for your nex
It is not yet fully [supported](https://kangax.github.io/compat-table/es6/) by browser vendors, but it's the future of JavaScript.

As of today, you need to transpile ES6 code into something understandable by current browsers, which is ES5.
For this purpose we support [Babel](https://babeljs.io). Make sure to require `'lotus/assets/es6'` to enable it.
For this purpose we support [Babel](https://babeljs.io). <strike>Make sure to require `'lotus/assets/es6'` to enable it.</strike>

## Sources

@@ -107,7 +107,7 @@ This release will ship with a new command: `lotus assets precompile`; which can

Assets are loaded from the sources of each application (including third party gems) and preprocessed or copied into the public directory of the project.

Each asset is compressed using [YUI Compressor](http://yui.github.io/yuicompressor) (which requires **Java 1.4+**).
Each asset is compressed using <strike>[YUI Compressor](http://yui.github.io/yuicompressor) (which requires **Java 1.4+**)</strike> one of the supported engines: YUI, UglifyJS2, Google Closure, Sass.
With this step we shrink the file size, to let browser to download them faster.

As last step, we produce another version of the same file that includes the checksum of the assets in the name (see the example below).
@@ -0,0 +1,147 @@
---
title: Announcing Lotus v0.6.0
date: 2016-01-12 15:42 UTC
tags: announcements
author: Luca Guidi
image: true
excerpt: >
Features: Assets, custom initializers, default Rake tasks, and destroy command.
---

This new release makes Lotus a complete web framework for Ruby.
It ships with the last important set of features that we planned: assets.

**We have now everything we need to build web applications with Lotus.**

## Features

### Assets

As of Lotus v0.6.0, we now have a full set of features for assets management, such as:

* [Helpers](/guides/helpers/assets)
* [Preprocessors](/guides/assets/preprocessors) ([Sass](http://sass-lang.com), [Less](http://lesscss.org), [ES6](http://es6-features.org), [JSX](https://jsx.github.io), [CoffeeScript](http://coffeescript.org), [Opal](http://opalrb.org), etc..)
* [Compressors](/guides/assets/compressors) ([YUI](http://yui.github.io/yuicompressor), [UglifyJS2](http://lisperator.net/uglifyjs), [Google Closure Compiler](https://developers.google.com/closure/compiler), [Sass](http://sass-lang.com), etc..)
* [Deployment](/guides/command-line/assets) (precompile, compress, checksum)
* [Content Delivery Network](/guides/assets/content-delivery-network)
* [Heroku support](/blog/2015-12-29-introducing-assets.html)
* [Third Party Gems](/guides/assets/overview) (eg. `bootstrap` gem will support soon Lotus out of the box)
* A new [Rack middleware](/guides/assets/overview) to serve static assets
* Lazy precompilation + cache in development mode

Thanks to [Leigh Halliday](https://github.com/leighhalliday), [Gonzalo Rodríguez-Baltanás Díaz](https://github.com/Nerian), [deepj](https://github.com/deepj), [Michael Deol](https://github.com/michaeldeol), [Benjamin Klotz](https://github.com/tak1n), [Kleber Correia](https://github.com/klebervirgilio) for their contributions and help.

[Read the [guides](/guides/assets/overview) and the [announcement](/blog/2015-12-29-introducing-assets.html)]

### Custom Initializers

For each application under `apps/`, now we can **optionally** have a special directory (eg. `apps/web/config/initializers`) where to put Ruby source files to initialize that specific application.
Starting from `v0.6.0`, new projects and applications will be generated with that directory.

Thanks to [Lucas Allan](https://github.com/lucasallan) for this new feature.

[Read the [guides](/guides/applications/initializers)]

### Default Rake Tasks

Lotus projects now ship with two default Rake tasks: `:preload` and `:environment`.
The first is a lightweight way to load **only** the configurations of a project, while the latter loads the entire application.
We can use them as requirement for our Rake tasks:

```ruby
# Rakefile
# ...
task print_info: :preload do
puts ENV['LOTUS_ENV']
puts defined?(UserRepository)
end
task clear_users: :environment do
UserRepository.clear
end
```

We can invoke these new taks with:

```shell
bundle exec rake print_info
# => "development"
# => nil
```

```shell
bundle exec rake clear_users
```

[Read the [guides](/guides/applications/rake)]

### Destroy Command

We have introduced a new CLI command `lotus destroy`.
It has the role of destroy applications (`apps/`), actions, entities, repositories, migrations, mailers and their related testing code.

```shell
bundle exec lotus destroy action web home#index
```

Thanks to [Tadeu Valentt](https://github.com/t4deu) and [Lucas Allan](https://github.com/lucasallan) for this feature.

## Minor Changes &amp; Improvements

Pluralizations can be [customized](https://github.com/lotus/utils/pull/90) by adding exceptions to default inflections.

Action generator is now [smarter](https://github.com/lotus/lotus/pull/414) and it can generate a route with the right HTTP verb, according to our REST conventions. Thanks to [Sean Collins](https://github.com/cllns).

Special thanks goes to [Tadeu Valentt](https://github.com/t4deu), [Pascal Betz](https://github.com/pascalbetz), [Andrey Deryabin](https://github.com/aderyabin), [Anton Davydov](https://github.com/davydovanton), [Caius Durling](https://github.com/caius), [Jason Charnes](https://github.com/jasoncharnes), [Sean Collins](https://github.com/cllns), and [Ken Gullaksen](https://github.com/kenglxn) for their work to make our CLI stronger than ever.

Thanks to [Neil Matatall](https://github.com/oreoshake) to prevent timing attacks for CSRF tokens comparision, [David Strauß](https://github.com/stravid) for making body parsing compatible with JSON API, [Karim Tarek](https://github.com/karimmtarek) and [Liam Dawson](https://github.com/liamdawson) for exception normalization across all our gems, [Vladislav Zarakovsky](https://github.com/vlazar) for making Force SSL compliant with Rack SPEC, while [Bernardo Farah](https://github.com/berfarah) fixed chunked responses, to [Karim Kiatlottiavi](https://github.com/constXife) for fixing HTML escape encoding, to [Rodrigo Panachi](https://github.com/rpanachi) for fixing CSRF form, to [Hélio Costa](https://github.com/hlegius) and [Pascal Betz](https://github.com/pascalbetz) for fixing how validations treat blank strings, to [Cẩm Huỳnh](https://github.com/huynhquancam) for making `#html` helper to accept blocks.

We're thankful for the help that [Hiếu Nguyễn](https://github.com/hieuk09), [Taylor Finnell](https://github.com/taylorfinnell), [Andrey Deryabin](https://github.com/aderyabin), [Cainã Costa](https://github.com/cfcosta), [Shin-ichi Ueda](https://github.com/skyriser), [Martin Rubi](https://github.com/cabeza-de-termo) offered for other minor improvement and fixes.

## Deprecations

### Ruby 2.0 &amp; 2.1

Ruby 2.0 and 2.1 are now deprecated.
We took this decision because MRI 2.0 will reach End Of Life (EOL) next month and because keeping 2.1 around would mean to leave our internals complex because of _"safe indifferent access"_.

Prior to MRI 2.2, `Symbol` instances weren't garbage collected.
This has caused security problems for Ruby applications.
If not properly filtered, untrusted input could've been lead to attacks where the server memory is entirely consumed by Ruby VM due to `Symbol` abuse.

To prevent this kind of attack, we always used strings for incoming HTTP parameters.
At the same time, we wanted to offer convenient access to these params via symbols (eg `params[:id]`).
To make this possible we had to carefully filter and convert data over and over.

By dropping 2.1, we can simplify our internal code because we don't have to worry about GC and symbols security threats.
At the same time we can provide minor perf improvements due to the lack of these conversions.

## Breaking Changes

There are several breaking changes due to assets features.

**If you're upgrading from an earlier version, please make sure to read the detailed [upgrade guide](/guides/upgrade-notes/v060) that we prepared.**
It will take a few minutes to get up and running again.

## What's Next?

Our focus for the next release (`v0.7.0`) will be about `Lotus::Model` and `Lotus::Validations`.
We want to make **stronger** and **flexible** the way we validate and persist data.

We recognized it's **too verbose** to always require **database mapping** even if it can be avoided (eg with SQL databases).
It's **not necessary** to instantiate an entity to write a record, repositories can **directly accept data** and persist it.

We want to **simplify** our day to day life with Lotus.

<div style="display: inline">

<iframe src="https://ghbtns.com/github-btn.html?user=lotus&repo=lotus&type=star&count=true&size=large" frameborder="0" scrolling="0" width="160px" height="30px"></iframe>

<a href="https://news.ycombinator.com/submit" class="hn-button" data-title="Announcing Lotus v0.6.0" data-url="http://lotusrb.org/blog/2016/01/12/announcing-lotus-060.html" data-count="horizontal" data-style="facebook">Vote on Hacker News</a>
<script type="text/javascript">var HN=[];HN.factory=function(e){return function(){HN.push([e].concat(Array.prototype.slice.call(arguments,0)))};},HN.on=HN.factory("on"),HN.once=HN.factory("once"),HN.off=HN.factory("off"),HN.emit=HN.factory("emit"),HN.load=function(){var e="hn-button.js";if(document.getElementById(e))return;var t=document.createElement("script");t.id=e,t.src="//hn-button.herokuapp.com/hn-button.js";var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(t,n)},HN.load();</script>
<script type="text/javascript">
reddit_url = "http://lotusrb.org/blog/2016/01/12/announcing-lotus-060.html";
</script>
<script type="text/javascript" src="//www.redditstatic.com/button/button1.js"></script>
</div>
Binary file not shown.
@@ -0,0 +1,23 @@
---
title: Lotus - Guides - Applications Initializers
---

# Initializers

Each single Lotus application within a project can **optionally** have one or more custom initializers.

<p class="notice">
Initializers are optional
</p>

They are run **after** the dependencies, the framework and the application code are loaded, but **before** the server or the console are started.

<p class="convention">
For a given application named <code>Web</code>, they MUST be placed under <code>apps/web/config/initializers</code>.
</p>

Their execution order is alphabetical.

<p class="warning">
Initializers are executed in alphabetical order.
</p>
@@ -0,0 +1,108 @@
---
title: Lotus - Guides - Applications Rake Tasks
---

# Rake Tasks

Lotus ships with default Rake tasks that can be used as _prerequisites_ by developers to build their own tasks.

```shell
% bundle exec rake -T
rake environment # Load the full project
rake preload # Preload project configuration
rake test # Run tests
```

## Environment

This Rake task:

1. Executes all `preload` steps
2. Load all the project code

Use this as a Rake task prerequisite when you **DO** need to access to project code (eg. entites, actions, views, etc..)

### Example

Imagine we want to build a Rake task that is able to access project code (eg. a repository)

```ruby
# Rakefile
task clear_users: :environment do
UserRepository.clear
end
```

```shell
bundle exec rake clear_users
```

<p class="notice">
The <code>:environment</code> Rake loads the entire project. It's slower than <code>:preload</code>, use it when you need to access project code.
</p>

## Preload

This Rake task is a fast way to preload:

* Gem dependencies in `Gemfile`
* The framework
* Project configurations such as env variables and application configurations (eg. `apps/web/application.rb`)

Use this as a Rake task prerequisite when you **DO NOT** need to access to project code (eg. entites, actions, views, etc..)

### Example

Imagine we want to build a Rake task that prints informations about our project:

```ruby
# Rakefile
task print_informations: :preload do
puts ENV['LOTUS_ENV'] # => "development"
puts ENV['BOOKSHELF_DATABASE_URL'] # => "postgres://localhost/bookshelf_development"
puts defined?(User) # => nil
end
```

```shell
% bundle exec rake print_informations
"development"
"postgres://localhost/bookshelf_development"
""
```

<p class="notice">
The <code>:preload</code> Rake task preloads projects and applications configurations. Use it when you need a fast way to access them.
</p>

## Test

This is the default Rake task, it runs the test suite

The following commands are equivalent:

```shell
% bundle exec rake
```

```shell
% bundle exec rake test
```

<p class="convention">
The <code>:test</code> Rake task is the default.
</p>

## Ruby Ecosystem Compatibility

Many Software as a Service (SaaS) of the Ruby ecosystem are modeled after Ruby on Rails.
For instance, Heroku expects to find the following Rake tasks in a Ruby application:

* `db:migrate`
* `assets:precompile`

For Heroku, there isn't a way to customize the deploy, so we're supporting these "standard" Rake tasks from Ruby on Rails.

**If you are in control of your deployment, don't rely on these Rake tasks, but please use `lotus` [command line](/guides/command-line/database), instead.**
@@ -0,0 +1,86 @@
---
title: Lotus - Guides - Assets Compressors
---

# Assets

## Compressors

Assets compression (aka minification) is a process to shrink the file size of a file in order to reduce the time that a browser needs to download it.
Usually, it's applied to javascripts and stylesheets.

In order to set one of the following engines, we need to open `apps/web/application.rb` and write:

```ruby
# apps/web/application.rb
module Web
class Application < Lotus::Application
configure do
assets do
javascript_compressor :builtin
stylesheet_compressor :builtin
# ...
end
end
end
end
```

If we want to skip compression, just comment one or both the lines above.

### JavaScript

We support the following engines:

* `:builtin` - It isn't efficient like the other algorithms, but it's a good starting point because it's written in **pure Ruby** and **it doesn't require external dependencies**.
* `:yui` - It's based on [Yahoo! YUI Compressor](http://yui.github.io/yuicompressor). It requires [`yui-compressor`](https://rubygems.org/gems/yui-compressor) gem and Java 1.4+
* `:uglifier` - It's based on [UglifyJS2](http://lisperator.net/uglifyjs). It requires [uglifier](https://rubygems.org/gems/uglifier) gem and Node.js
* `:closure` - It's based on [Google Closure Compiler](https://developers.google.com/closure/compiler). It requires [`closure-compiler`](https://rubygems.org/gems/closure-compiler) gem and Java

<p class="warning">
In order to use <code>:yui</code>, <code>:uglifier</code> and <code>:closure</code> compressors, you need to add the corresponding gem to <code>Gemfile</code>.
</p>

### Stylesheet

We support the following engines:

* `:builtin` - It isn't efficient like the other algorithms, but it's a good starting point because it's written in **pure Ruby** and **it doesn't require external dependencies**.
* `:yui` - It's based on [Yahoo! YUI Compressor](http://yui.github.io/yuicompressor). It requires [`yui-compressor`](https://rubygems.org/gems/yui-compressor) gem and Java 1.4+
* `:sass` - It's based on [Sass](http://sass-lang.com). It requires [sass](https://rubygems.org/gems/sass) gem

<p class="warning">
In order to use <code>:yui</code>, and <code>:sass</code> compressors, you need to add the corresponding gem to <code>Gemfile</code>.
</p>

### Custom Compressors

We can use our own compressor for **both JS and CSS**.
It **MUST** respond to `#compress(filename)` and return a `String` with the minification output.

```ruby
class MyCustomJavascriptCompressor
def compress(filename)
# ...
end
end
```

Then we can use it with our configuration:

```ruby
# apps/web/application.rb
module Web
class Application < Lotus::Application
configure do
assets do
javascript_compressor MyCustomJavascriptCompressor.new
stylesheet_compressor :builtin
# ...
end
end
end
end
```

0 comments on commit b3996b7

Please sign in to comment.
You can’t perform that action at this time.