Permalink
Browse files

Merge pull request #399 from hanami/guide-command-line-plugins

Guide command line plugins
  • Loading branch information...
marionschleifer committed Oct 20, 2017
2 parents bfc67fd + 6ceb3f1 commit e76fcb0521da174fdd0518356a615b5465cd2392
@@ -2,6 +2,7 @@

Bundler.require(:default, ENV['SITE_ENV']) if defined?(Bundler)

require 'yaml'
require 'ostruct'
require 'rack/utils'
require 'middleman-syntax'
@@ -112,6 +113,16 @@ def article_image_url(article)
GUIDES_ROOT = 'source/guides'.freeze
GUIDES_EDIT_URL = 'https://github.com/hanami/hanami.github.io/edit/build/'.freeze

def guides
@guides ||= {}

version = current_page.data.version == 'head' ? 'head' : "#{version}" #guides_path(current_page, current_page.data.version)
return @guides[version] unless @guides[version].nil?

yaml = YAML.load_file("#{GUIDES_ROOT}/#{version}/guides.yml")
@guides[version] = JSON.parse(yaml.to_json, object_class: OpenStruct)
end

def guide_title(item, version = nil)
item.title || item.path.split('-').map(&:capitalize).join(' ')
end
@@ -195,13 +206,13 @@ def guides_edit_article(source)

ROOT_GUIDE_PAGE_REGEXP = %r(\A/guides/([\d\.|head]+/)?\z)

def breadcrumbs(page, **payload)
def breadcrumbs(page, guides)
metadata = page.metadata
version = metadata[:page]['version']
version_text = version == 'head' ? nil : "/ #{link_to(version, "/guides/#{version}")} "
page_title = metadata[:page]['title'].split(' - ').last

category = data.guides.categories.select do |c|
category = guides.categories.select do |c|
c['pages'].map { |p| p['path'] }.include?(page.url.split('/').last)
end.first

@@ -3,17 +3,15 @@ title: "Guides - Command Line: Applications"
version: 1.0
---

# Command Line

## Applications
# Applications

We can generate a new project via `hanami new`, followed by the name that we want to use.

```shell
% hanami new bookshelf
```

### Database
## Database

The default database engine is SQLite.

@@ -28,7 +26,7 @@ It supports:
* `mysql`
* `mysql2`

### Testing Framework
## Testing Framework

The default testing framework is Minitest.

@@ -3,13 +3,11 @@ title: "Guides - Command Line: Assets"
version: 1.0
---

# Command Line

## Assets
# Assets

We can manage assets via the command line.

### Precompile
## Precompile

This command is useful for **deployment** purposes.

@@ -36,7 +34,7 @@ It generates a fingeprint manifest that lists all the assets and their checksum

This is used by assets helpers to resolve an asset name into a relative path.

### Example
## Example

Let's say we have a project with three applications: `admin`, `metrics` and `web`.

@@ -3,9 +3,7 @@ title: "Guides - Command Line: Database"
version: 1.0
---

# Command Line

## Database
# Database

We can manage our database via the command line.

@@ -18,7 +16,7 @@ We can manage our database via the command line.
The [adapter](/guides/1.0/models/overview) is set in `lib/bookshelf.rb`.
It uses an environment variable, defined in the `.env.*` files at the root of the project.

### Create
## Create

With `db create` we can create the database for the current environment.

@@ -34,7 +32,7 @@ To be able to run tests, test database has to be explicitly created

In order to preserve production data, this command can't be run in the production environment.

### Drop
## Drop

With `db drop` we can drop the existing database for the current environment.

@@ -44,7 +42,7 @@ With `db drop` we can drop the existing database for the current environment.

In order to preserve production data, this command can't be run in the production environment.

### Migrate
## Migrate

With `db migrate` we can run [migrations](/guides/1.0/migrations/overview) found in `db/migrations`.

@@ -72,7 +70,7 @@ For instance, if we want to **rollback** the changes from `20150613165900_create

**This command is available in ALL the environments and ALL the SQL databases.**

### Prepare
## Prepare

Prepares database for the current environment. This command can't be run in the production environment.

@@ -88,7 +86,7 @@ When we run `db prepare` it:

This command SHOULD be used as a database setup command.

### Apply
## Apply

This is an experimental feature.
When an application is developed after years, it accumulates a large number of migrations, this slows down database operations for development and test (CI).
@@ -107,7 +105,7 @@ When we run `db apply`, it:

This command is available only in the development environment.

### Version
## Version

Prints current database version. Given the following migrations:

@@ -3,14 +3,12 @@ title: "Guides - Command Line: Destroy"
version: 1.0
---

# Command Line

## Destroy
# Destroy

Hanami has convenient [code generators](/guides/1.0/command-line/generators) to speed up our development process.
If we commit a mistake, we can destroy what we just generated via `hanami destroy` command.

### Applications
## Applications

With the Container architecture, we can have multiple Hanami applications running under `apps/`.
We can [generate new applications](/guides/1.0/command-line/generators) for different components that we want to add to our project.
@@ -23,7 +21,7 @@ To destroy one of them:

This removes an application named `Admin` under `apps/admin`.

### Actions
## Actions

We can destroy an action along with the corresponding view, template, route and test code with one command.

@@ -40,7 +38,7 @@ The first argument, `web`, is the name of the target application in a Container

The argument `books#show` is the name of the controller and the action separated by the number sign (`#`).

### Models
## Models

We can destroy a model.

@@ -50,7 +48,7 @@ We can destroy a model.

It removes an entity with the corresponding repository and test code.

### Migrations
## Migrations

We can destroy a migration.

@@ -60,7 +58,7 @@ We can destroy a migration.

It deletes the migration with the corresponding name (eg. `db/migrations/20150621181347_create_books.rb`).

### Mailers
## Mailers

We can destroy a mailer.

@@ -3,13 +3,11 @@ title: "Guides - Command Line: Generators"
version: 1.0
---

# Command Line

## Generators
# Generators

Hanami has convenient code generators to speed up our development process.

### Applications
## Applications

With Hanami architecture, we can have multiple Hanami applications running under `apps/`.
The default application is called `Web` and lives under `apps/web`.
@@ -22,7 +20,7 @@ We can generate new applications for different components that we want to add to

This generates an application named `Admin` under `apps/admin`.

### Actions
## Actions

Generate an action along with the corresponding view, template, route and test code with one command.

@@ -46,7 +44,7 @@ If you wish to generate action with specific method, you can do that by using th
% bundle exec hanami generate action web books#create --method=post
```

#### Route
### Route

The generated route is named after the controller name.

@@ -78,7 +76,7 @@ This should help you route using [RESTful resources](/guides/1.0/routing/restful

You can also set the HTTP method by specifying a `--method` argument when calling `hanami generate action`.

### Models
## Models

Generate an entity and a repository with a single command

@@ -109,7 +107,7 @@ Hanami::Model.migration do
end
```

### Migrations
## Migrations

Generate a database migration

@@ -120,7 +118,7 @@ Generate a database migration

It generates an empty migration with the UTC timestamp and the name we have specified: `db/migrations/20161112113203_create_books.rb`.

### Mailers
## Mailers

Generate a mailer

@@ -143,7 +141,7 @@ lib
# ...
```

### Secret
## Secret

Generate a HTTP sessions secret for an application.

@@ -3,9 +3,7 @@ title: "Guides - Command Line: Routes"
version: 1.0
---

# Command Line

## Routes
# Routes

In order to print the routes defined by all the applications, use:

@@ -3,9 +3,7 @@ title: "Guides - Command Line: Version"
version: 1.0
---

# Command Line

## Version
# Version

By running `hanami version` we can see the current version of the framework that we are using.

File renamed without changes.
@@ -3,17 +3,15 @@ title: "Guides - Command Line: Applications"
version: head
---

# Command Line

## Applications
# Applications

We can generate a new project via `hanami new`, followed by the name that we want to use.

```shell
% hanami new bookshelf
```

### Database
## Database

The default database engine is SQLite.

@@ -28,7 +26,7 @@ It supports:
* `mysql`
* `mysql2`

### Testing Framework
## Testing Framework

The default testing framework is Minitest.

@@ -37,7 +35,7 @@ We can use the `--test` argument to specify a different framework, from the list
* `minitest` (default)
* `rspec`

### Template Engine
## Template Engine

The default template engine is ERB.

@@ -3,13 +3,11 @@ title: "Guides - Command Line: Assets"
version: head
---

# Command Line

## Assets
# Assets

We can manage assets via the command line.

### Precompile
## Precompile

This command is useful for **deployment** purposes.

@@ -36,7 +34,7 @@ It generates a fingeprint manifest that lists all the assets and their checksum

This is used by assets helpers to resolve an asset name into a relative path.

### Example
## Example

Let's say we have a project with three applications: `admin`, `metrics` and `web`.

Oops, something went wrong.

0 comments on commit e76fcb0

Please sign in to comment.