Tenon
License
This project uses the MIT-LICENSE. Do whatever you want with it as long as you don’t violate the licenses of the various open source pieces on which it depends.
Installation
In your Gemfile
gem 'tenon'
and then bundle install.
in config/application.rb:
require 'active_record/railtie'
in config/routes.rb:
mount Tenon::Engine => '/tenon'
Run command:
$ rake tenon:install:migrations
$ rake db:migrate
You will need to have a database set up at this point. Currently Tenon requires that you use postgres.
Running rake db:migrate probably threw up a devise error. Create config/initializers/devise.rb and paste:
Devise.setup do |config|
## paste the secret key line from the error output ##
end
Run that command again:
$ rake db:migrate
Install the Tenon helpers in app/controllers/application_controller.rb:
helper Tenon::Engine.helpers
Install the necessary files to run and customize Tenon (this is now required):
$ rails generate tenon:install
To run seed data (such as creating an admin user) from Tenon, open console and run:
ENV['PASSWORD'] = 'password' # or something at least 8 chars long
Tenon::Engine.load_seed
Restart your app and navigate to /tenon
If you want to be able to use rspec, which would be good, you will also need to run:
bundle exec rails generate rspec:install
Scaffolding
TODO: Write this section
Item Revisions/History
TODO: Write this section
Internationalization
Although Tenon is currently anglocentric it supports the inclusion of additional languages and provides an interface for managing content in multiple languages.
To add internationalized fields, follow these steps:
-
Add our ‘translates’ gem to your Gemfile and then bundle install
gem 'translates', git: 'https://github.com/factore/translates.git'
-
Tell Tenon which languages you want to support in config/initializers/tenon.rb (You don’t need to add English, Tenon always assumes its in use.)
config.languages = { "French" => :fr, "German" => :de # etc. }
-
Add a language yml file in config/locales/ for each language defined above, or rails will have a fit, eg ‘config/locales/fr.yml’
-
Create or update config/i18n_fields.yml to tell Tenon which fields you would like to have internationalized.
tables: cars: - title - description events: - title - location - description If you want to add internationalization to the default Tenon models you should make your i18n_fields.yml look like this: tables: tenon/events: - title - location tenon/pages: - title - seo_title - seo_keywords - seo_description tenon/posts: - title - excerpt - seo_title - seo_keywords - seo_description
-
Generate and run the internationalization migration. The generator will only try to create columns that don’t already exist, so you can use this generator multiple times throughout the development of your application.
rails generate tenon:i18n_migrations rake db:migrate
-
Update your models to make sure your attributes are translated
class MyModel < ActiveRecord::Base include Translates # plain old rails attributes translates :title # tenon_content tenon_content :description, i18n: true end
-
Update your tenon views to add the language navigation helper, where needed:
# app/views/tenon/cars/_form.html.haml - content_for :sidebar do .sidebar .content ... = i18n_language_nav(:cars) ...
-
While there, make sure you are using ‘autosaving_form_for’ instead of ‘form_for’ to create your forms. By doing this, Tenon will automatically update the labels when the different languages are selected.
-
Make sure your routes are configured according to your needs and the I18n.locale is being set somehow (see Rails documentation for more info: guides.rubyonrails.org/i18n.html)
Once you’ve done this and restarted your app you will see a language selection nav in the sidebar of each Tenon form that has internationalized fields. On the front end, attributes on your Tenon models will be translated correctly, based on I18n.locale.