Giter VIP home page Giter VIP logo

sir-trevor-rails's Introduction

Sir Trevor Rails

A Rails gem for integrating Sir Trevor JS into your Rails 3/4 application.

Upgrade guide from v0.4.0-rc.1

Version 0.4.0 represents a major refactor and contains significant API changes.

  • The SirTrevor gem has been renamed from sir-trevor-rails to sir_trevor_rails you will need to update your Gemfile.
  • There are no more form helpers or view helpers so relace f.sir_trevor_text_area :content with f.text_area :content.
  • SirTrevor JS and it's dependencies are no longer bundled with the gem and need to be downloaded and installed manually or with bower. See the SirTrevor JS repo for more.
  • In your model, register your SirTrevor content like this sir_trevor_content :content where :content is the name of the field on your where you store SirTrevor content.
  • In your views, you no longer need to use the render_sir_trevor helper. Instead, simply render your content like this <%= render @item.content %>

Usage

Add Sir Trevor to your Gemfile

gem 'sir_trevor_rails'
bundle install

Include Sir Trevor JS in your project following the instructions set out here

Generators: Views

Grab all of the default block type partials by running the following generator command:

rails g sir_trevor_rails:views

This will copy all of the SirTrevor block partials into app/views/sir_trevor/blocks/

Rendering

In your models pass the attribute name of your Sir Trevor content to sir_trevor_content

sir_trevor_content :content

In your view files, call render to display the Sir Trevor content

<%= render @item.content %>

Handling image uploads

We don't provide a default image uploader out of the box, because everyone will have different requirements. To see an example of an image uploader, please refer to our Rails examples in the Sir Trevor JS repository.

Handling markdown

Use the sir_trevor_markdown method in your custom block partials to correctly parse the markdown in a block

Querying the block content

Use the following methods to query the Sir Trevor content

@item.content.has_block_of_type?(:image)

Does this content have an image block?

@item.content.first_block_of_type(:video)

Return the first video block in the content

Add custom methods for block content

Create an initializer config/initializers/sir_trevor_rails.rb

Write your method in the initializer:

class SirTrevorRails::BlockArray
  def your_custom_method_here
    # some code
  end
end

Call your method on the ST content

@item.content.your_custom_method

Generators: Blocks

Run the blocks generator to create templates for your custom blocks

rails g sir_trevor_rails:block my_custom_block

This will generate an html file for rendering the block, a javascript file for the editor and a ruby block class.

Block Classes

Ruby block classes can be used like decorators for the block content. See the tweet block class for an example

Requirements

  • Rails 3.x/4.x

To do

  • Add tests

Licence

Sir Trevor Rails is released under the MIT Licence

Changelog

See the CHANGELOG

sir-trevor-rails's People

Contributors

andflett avatar arbarlow avatar askl56 avatar cbeer avatar cjbell avatar danbee avatar higgis avatar icedtoast avatar jonduarte avatar lukaszsagol avatar milushov avatar raffij avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.