Git Product home page Git Product logo

inline_view_component's Introduction

InlineViewComponent

This gem allows your ViewComponents to define template strings within the class definition. You should be able to use any templating language your rails app supports (ERB, HAML, Slim...). There's also custom syntax highlighting for heredoc templates for Sublime Text.

Usage

Include the InlineViewComponent mixin and then specify your template string with template(string). Be sure to delete your component's external template file or ViewComponent will raise an error.

Examples

class ErbComponent < ViewComponent::Base
  include InlineViewComponent

  def message
    "Hello World!"
  end

  template <<~ERB
    <p> <%= message %> </p>
  ERB
end
class HamlComponent < ViewComponent::Base
  include InlineViewComponent

  def message
    "Hello HAML!"
  end

  template <<~HAML, :haml
    %p= message
  HAML
end

You can provide any template format you have installed as an optional second argument to the template method

  template <<~SLIM, :slim
    h1 Hello World!
  SLIM

Installation

Add this line to your application's Gemfile:

gem 'inline_view_component'

And then execute:

$ bundle

Or install it yourself as:

$ gem install inline_view_component

Syntax Highlighting

Syntax highlighting for Sublime Text is available. Download this file and add it to your Sublime User package. Then open your ruby files in the Ruby (Custom) syntax (or choose View -> Syntax -> Open All with current extention as... to use it automatically).

To get syntax highlighting to work use ERB, HAML, or SLIM as the delimiter for your heredoc string e.g.

template <<~HAML, :haml
  %h1 A really great template
HAML

TODO

This is an early release. Contributions are welcome!

  • add syntax highlighting for more editors (VS Code, vim, ...)

Contributing

Send a pull request.

License

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

inline_view_component's People

Contributors

existentialmutt avatar rrosen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

inline_view_component's Issues

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.