Project

micro_cms

0.0
Low commit activity in last 3 years
No release in over a year
Provides a cms block which can be edited inline
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

Runtime

> 6.0
 Project Readme

MicroCms

Provides editable inline content blocks to modify your content on the fly.

Dependencies

Usage

To provide an editable content block, use the cms_block helper method in your view, e.g.:

= cms_block 'my.unique.block.identifier'
  h1 Default
  p This is my default content

To print the content in readonly mode, use the cms_content helper method in your view, e.g:

= cms_content 'my.unique.block.identifier'
  p My content if there's no content block yet

It's best to write an own helper method which also does authentication like

def cms(path, &block)
  if current_user&.write_cms?
    cms_block(path, &block)
  else
    cms_content(path, &block)
  end
end

Installation

Add this line to your application's Gemfile:

gem 'micro_cms'

And then execute:

$ bundle

Or install it yourself as:

$ gem install micro_cms

In your app, run

bin/bundle exec rake micro_cms:install:migrations
bin/rails db:migrate

to copy the migrations.

Mount the engine routes in you config/routes.rb file:

mount MicroCms::Engine => '/micro_cms'

Usage with Sprockets

Require the JavaScript (e.g. //= require micro_cms) and all styles (e.g. @import 'micro_cms';').

Usage with Webpacker

Make sure that you import rails/ujs like that in your application.js:

import Rails from '@rails/ujs';
Rails.start();
...
window.Rails = Rails;

The last line makes the Rails scope global (since we inline the script, this is needed).

Now you have to include the helper to your ApplicationHelper:

module ApplicationHelper
  include MicroCms::ApplicationHelper
  ...
end

Now you can use the helper to inline the needed scripts via app/views/layouts/application.html.slim. It's strongly recommended to check first, if the user is allowed to edit (but this is not part of this gem):

- if user_signed_in? # not part of this gem!
  = micro_cms_asset_tags

Configuration

app/config/initializers/micro_cms.rb:

MicroCms.configure do |config|
  config.ckeditor_configuration_file = 'ckeditor/config.js' # Custom ckeditor config. Optional
end

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/renuo/i18n-docs. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.

License

The gem is available as open source under the terms of the MIT License.