Textblocks

Gem Version Build Status Code Climate Test Coverage

Editable, revisioned front-end texts for rails apps.

Txtblx provides a simple way to allow Active Admin users to edit interface copy.

Installation

Add txtblx to you Gemfile

gem 'txtblx'

Migrate your database:

bundle exec rake txtblx:install:migrations
bundle exec rake db:migrate

Load helpers in your application controller:

helper(Txtblx::Engine.helpers)

Use in Templates

<h1>Welcome<h1>

<%= txt('homepage.welcome') %>

Active Admin Integration

Txtblx comes with an ActiveAdmin page to manage Textblocks. Load it in an initializer:

# config/initializers/txtblx.rb
Txtblx.configure do |config|
  config.load_active_admin
end

CanCan Integration

Txtblx provides default CanCan Abilities for its model.

There are two sets of abilities:

  • Full
  • Editor can only change text and may not create or delete textblocks.

Use the AbilityMixin to grant them to your user model inside your Ability-class.

# app/models/ability.rb
class Ability
  include CanCan::Ability
  include Txtblx::AbilityMixin

  def initialize(user)
    txtblx_editor_abilities(user)

    if user.admin?
      txtblx_full_abilities(user)
    end
  end
end

Configuration

Txtblx uses auto_html to convert text to HTML. To change the auto_html config create an initializer in your app:

# config/initializers/txtblx.rb
Txtblx.configure do |config|
  config.auto_html_block = Proc.new do
    # you config here, for example:
    html_escape
    image
    link(:target => "_blank", :rel => "nofollow")
    simple_format
  end
end

Import/Export Rake Tasks

Txtblx can export the Textblocks to a set of markdown files by running:

bundle exec rake txtblx:export

For each Textblock one markdown file will be written into the directory 'textblocks' in your rails root dir.

You can create Textblock instances from these file by running:

bundle exec rake txtblx:import