Giter VIP home page Giter VIP logo

decorators's Introduction

Decorators Plugin Build Status

This is a very simple plugin that adds support for decorators to your Rails application. Effectively all that this does is allow you to register paths in which to search for decorators which are then loaded at the appropriate point in your application's initialisation process.

Decorators must follow this naming convention:

app/decorators/<at least one subdirectory>/something_decorator.rb

This is an example of a decorator that will be loaded:

app/decorators/controllers/pages_controller_decorator.rb

These are examples of decorators that won't be loaded:

app/decorators/pages_controller_decorator.rb
app/decorators/controllers/pages_controller.rb

The important parts are being inside a sub directory of app/decorators and having _decorator.rb at the end of the file's name.

How to install

In your Gemfile, add the gem:

gem 'decorators', '~> 1.0.4'

Now, run bundle install and the gem should install.

How to use

There really is just one method to call; Decorators#register!. Simply pass one path or many paths to the method to register paths to search inside for decorators to be loaded from.

require 'decorators'
Decorators.register! Rails.root

Or for many paths:

require 'decorators'
Decorators.register! Rails.root, Rails.root.join('vendor', 'extensions', 'extension_with_decorators')

Avoiding Rails development mode reloading issues (example)

If you are loading this from within a Rails engine definition make sure you require the decorators library in the standard way, from outside of any method definitions:

+require 'decorators'
+
 module Namespaced
   class Engine < Rails::Engine

   initializer 'load decorators' do
-    require 'decorators'
     Decorators.register! Rails.root, Rails.root.join('vendor', 'extensions', 'namespaced')
   end
 end

If this is happening in the main application you can avoid this in config/application.rb:

 require File.expand_path('../boot', __FILE__)

 require 'rails/all'
+require 'decorators'

 if defined?(Bundler)
   # etc

License

Decorators is released under the MIT license and is copyright (c) 2013 Philip Arndt

decorators's People

Contributors

parndt avatar simi avatar gwagener avatar jswanner avatar keram avatar radar avatar ugisozols avatar

Watchers

Mark Jackson avatar James Cloos avatar  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.