• Stars
    star
    150
  • Rank 240,767 (Top 5 %)
  • Language
    Ruby
  • License
    MIT License
  • Created almost 12 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Rails gem for Sir Trevor integration.

Sir Trevor Rails

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

Upgrade guide to v0.6.0

There is a breaking change which needs to be applied if you've defined custom ruby blocks.

Create an initializer config/initializers/sir_trevor_rails.rb

Add your custom block types in the initializer:

class SirTrevorRails::Block
  def self.custom_block_types
    # Type should be string based and prefix of your class name.
    ["Custom"] # Would relate to CustomBlock
  end
end

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 block types with custom methods

Create an initializer config/initializers/sir_trevor_rails.rb

Add your custom block types in the initializer:

class SirTrevorRails::Block
  def self.custom_block_types
    # Type should be string based and prefix of your class name which would be for the following.
    # TextBlock, HeadingBlock, CustomBlock
    ["Text", "Heading", "Custom"]
  end
end

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/5.x/6.x

To do

  • Add tests

Licence

Sir Trevor Rails is released under the MIT Licence

Changelog

See the CHANGELOG

More Repositories

1

sir-trevor-js

Rich content editing entirely re-imagined for the web
JavaScript
4,515
star
2

sir-trevor-blocks

A place for Sir Trevor BlockTypes
JavaScript
162
star
3

isthetoiletfree

Python
103
star
4

passwordless_auth

A library for simple passwordless authentication
Elixir
48
star
5

css-patterns

CSS
43
star
6

restful-authentication-facebook-connect-tutorial

Restful Authentication Facebook Connect Tutorial
Ruby
34
star
7

eventable

JavaScript
32
star
8

pharod

Docker container names to DNS records that can be resolved locally
Go
28
star
9

allele

A Ruby on Rails app template for even rapid-er prototyping.
Ruby
23
star
10

conan

Conan the Deployer
Ruby
20
star
11

front-end-london

The Front-end London website
JavaScript
20
star
12

Tasky

Sample Continuous Integration project.
15
star
13

bigbird

JavaScript
15
star
14

redux-action-logging

Redux testing utility middleware to log actions received by a store without mocking that store.
JavaScript
10
star
15

croppy

Scales and crops images to specific aspect ratios
JavaScript
9
star
16

tilly

A Slack bot to run standups, with no weird commands to remember
Go
7
star
17

ccdash

Simple build dashboard that understands cctray XML.
JavaScript
7
star
18

bzzzt

Python
7
star
19

coding-club

6
star
20

tweetparser

Extract content from tweets
Ruby
6
star
21

calappy

An iOS app to show an at-a-glance view of a Google Calendar resource's day
Objective-C
5
star
22

lazy_context

Elixir
4
star
23

css-guide-example

CSS
4
star
24

mixpanel_plug

A plug-based approach to Mixpanel tracking with Elixir
Elixir
4
star
25

password-store

Our fork of http://zx2c4.com/projects/password-store/
Shell
4
star
26

sxswagram

Some of the Many go to SXSW 2011
JavaScript
4
star
27

BzzztTray

Objective-C
4
star
28

votr

A super simple voting app we're using for the FEL One Day event
Ruby
4
star
29

parameter_cleaner

Strip angle brackets from Rails parameters at input, providing an extra level of security against XSS vulnerabilities.
Ruby
3
star
30

etcd-package

Debian package for etcd and etcdctl
Shell
3
star
31

roger

A little runit-able, cron-style scheduler
Go
3
star
32

moltar

Our developer tool for operating over sets of AWS instances, tagged with well-known metadata.
Go
2
star
33

tansit

deb-s3-as-a-service
Haskell
2
star
34

front-end-new-york

Website for FENY
CSS
2
star
35

metallus

Build Debian packages with Docker
Python
2
star
36

assert_valid_html

Check HTML validity without using an external web service
Ruby
2
star
37

environmentor

Ruby config management with a strong, checked schema and mapping from environment
Ruby
2
star
38

homebrew-custom

Formulae for our own tools
Ruby
1
star
39

cereal

Rails serialization, the simple way
Ruby
1
star
40

madebymany.github.com

Ruby
1
star
41

packages

ubuntu pkg creation scripts
Shell
1
star
42

Knightmare

Game
JavaScript
1
star
43

nightofthedigitaldead

Night of the Digital Dead Chrome extension
JavaScript
1
star
44

techdu_web

CSS
1
star
45

scormtrooper

Ruby gem for parsing SCORM packages
Ruby
1
star
46

nephelae

Nephelae runs as a daemon and sends custom stats such as disk space, memory usage to Cloud Watch on a regular basis
Ruby
1
star
47

clippy

Ruby
1
star
48

activeresource-nestful

Ruby
1
star
49

spree_country_pricing

Variant Country Pricing for Spree
Ruby
1
star