All Projects → pitr → Angular Rails Templates

pitr / Angular Rails Templates

Licence: mit
Use your angular templates with rails' asset pipeline

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to Angular Rails Templates

Letter opener web
A web interface for browsing Ruby on Rails sent emails
Stars: ✭ 513 (-10.94%)
Mutual labels:  rails
Serviceworker Rails
Use Service Worker with the Rails asset pipeline
Stars: ✭ 535 (-7.12%)
Mutual labels:  rails
Prosopite
🔍 Rails N+1 queries auto-detection with zero false positives / false negatives
Stars: ✭ 555 (-3.65%)
Mutual labels:  rails
Ajax Datatables Rails
A wrapper around DataTable's ajax methods that allow synchronization with server-side pagination in a Rails app
Stars: ✭ 520 (-9.72%)
Mutual labels:  rails
Activerecord Multi Tenant
Rails/ActiveRecord support for distributed multi-tenant databases like Postgres+Citus
Stars: ✭ 526 (-8.68%)
Mutual labels:  rails
Stateful enum
A very simple state machine plugin built on top of ActiveRecord::Enum
Stars: ✭ 546 (-5.21%)
Mutual labels:  rails
Zero downtime migrations
Zero downtime migrations with ActiveRecord 3+ and PostgreSQL
Stars: ✭ 513 (-10.94%)
Mutual labels:  rails
Administrate
A Rails engine that helps you put together a super-flexible admin dashboard.
Stars: ✭ 5,250 (+811.46%)
Mutual labels:  rails
Autolab
Course management service that enables auto-graded programming assignments.
Stars: ✭ 528 (-8.33%)
Mutual labels:  rails
Gitlabhq
GitLab CE Mirror | Please open new issues in our issue tracker on GitLab.com
Stars: ✭ 22,798 (+3857.99%)
Mutual labels:  rails
Fuzzapi
Fuzzapi is a tool used for REST API pentesting and uses API_Fuzzer gem
Stars: ✭ 521 (-9.55%)
Mutual labels:  rails
Rails email preview
Preview and edit app mailer templates in Rails.
Stars: ✭ 524 (-9.03%)
Mutual labels:  rails
Cancancan
The authorization Gem for Ruby on Rails.
Stars: ✭ 5,046 (+776.04%)
Mutual labels:  rails
Terraforming Rails
Terraforming legacy Rails applications guides and tools
Stars: ✭ 517 (-10.24%)
Mutual labels:  rails
Social Share Button
Helper for add social share feature in your Rails app. Twitter, Facebook, Weibo, Douban ...
Stars: ✭ 567 (-1.56%)
Mutual labels:  rails
Graphql Ruby
Ruby implementation of GraphQL
Stars: ✭ 4,931 (+756.08%)
Mutual labels:  rails
Annict
The platform for anime addicts built with Rails and Stimulus.js.
Stars: ✭ 542 (-5.9%)
Mutual labels:  rails
Activeadmin addons
Extends ActiveAdmin to enable a set of great optional UX improving add-ons
Stars: ✭ 574 (-0.35%)
Mutual labels:  rails
Webpacker
Use Webpack to manage app-like JavaScript modules in Rails
Stars: ✭ 5,282 (+817.01%)
Mutual labels:  rails
Devise
Flexible authentication solution for Rails with Warden.
Stars: ✭ 22,088 (+3734.72%)
Mutual labels:  rails

Angular Rails Templates

Gem Version Coverage Status Code Climate Issue Stats Issue Stats Stories in Ready

Adds your HTML templates into Angular's $templateCache using Rails asset pipeline.

IMPORTANT: for Rails 4.2+ use version 1.0+ of this gem. For Rails 3 - 4.1 use version 0.x

Branch Build Status
master Build Status
0-x-stable Build Status

It removes the need for AJAX calls to retrieve the templates (or for you to manually set them into the DOM).

Usage

1. Add the Gem

In Gemfile

gem 'angular-rails-templates'

2. Include Templates in Rails Asset Pipeline

Then, in your application.js file, require angular-rails-templates and your templates:

//= require angularjs
// ...
//= require angular-rails-templates
//
// Templates in app/assets/javascript/templates
//= require_tree ./templates
// OR
// Templates in app/assets/templates (but see step 5)
//= require_tree ../templates

Make sure to require angular-rails-templates before you require your templates.

Name your templates like you would name any other Rails view. The .html part is required. If it is not present your views will not be added to angular's template cache.

foo.html
foo.html.erb
foo.html.haml
foo.html.slim

Angular Rails Templates will try to load support for the following markups if their gems are present:

Extension Required gem
.erb -
.str -
.haml haml
.slim slim
.md liquid, rdiscount, redcarpet, bluecloth, kramdown, maruku

See Advanced if you would like to use other markup languages.

3. Add a Dependency in your Angular Application Module

Your Angular module needs to depend on the templates module. (configurable, see Advanced Configuration)

angular.module('myApplication', ['templates']);

4. Use your Templates

No matter what the source file extension is, your template's url will be #{base_name}.html

For example:

main.html => main.html
widget.html.haml => widget.html
modals/confirm.html.slim => modals/confirm.html
modals/dialog.html.slim.erb.str => modals/dialog.html # don't do this

The templates can then be accessed via templateUrl as expected:

// Template: app/assets/templates/yourTemplate.html.haml
{
  templateUrl: 'yourTemplate.html'
}

Or anything else that uses $templateCache or $templateRequest

<div ng-include='"yourTemplate.html"'></div>

5. Avoid name collisions

If you have app/assets/javascript/user.js and app/assets/templates/user.html, the former one will actually hide the latter. This is due to how Rails asset pipeline sees asset files, both are served under /assets/user.js. Please use namespacing to combat this issue.

Advanced Configuration

Angular Rails Templates has some configuration options that can be set inside config/application.rb

Here are their default values:

# config/application.rb
config.angular_templates.module_name    = 'templates'
config.angular_templates.ignore_prefix  = %w(templates/)
config.angular_templates.inside_paths   = ['app/assets']
config.angular_templates.markups        = %w(erb str haml slim md)
config.angular_templates.extension      = 'html'

Configuration Option: module_name

This configures the module name that your templates will be placed into. It is used to generate javascript like:

angular.module("<%= module_name %>")...

Although it is not recommended, you can set module_name to the name of your main application module and remove require angular-rails-templates from your javascript manifest to have your templates directly injected into your app.

Configuration Option: ignore_prefix

If you place your templates in app/assets/templates this option is mostly useless.

ignore_prefix will be stripped from the beginning of the templateUrl it reports to angularjs.

Since the default ignore_prefix is [templates/], any templates placed under app/assets/javascripts/templates will automatically have short names. If your templates are not in this location, you will need to use the full path to the template.

You can set config.angular_templates.ignore_prefix to change the default ignore prefix. Default is [templates/].

// Templates in: app/assets/javascripts/templates (default)
// ignore_prefix: templates/ (default)
{
  templateUrl: 'yourTemplate.html'
}
// This won't work:
{
  templateUrl: 'templates/yourTemplate.html'
}
// Templates in: app/assets/javascripts/my_app/templates (custom)
// ignore_prefix: templates/ (default)
{
  templateUrl: 'my_app/templates/yourTemplate.html'
}

// ignore_prefix: my_app/templates/ (custom)
{
  templateUrl: 'yourTemplate.html'
}

Configuration Option: inside_paths

Templates only from paths matched by inside_paths will be used. By default anything under app/assets can be templates. This option is useful if you are using this gem inside an engine. Also useful if you DON'T want some files to be processed by this gem (see issue #88)

Configuration Option: markups

Any markup that Tilt supports can be used, but you may need to add a gem to your Gemfile. See Tilt for a list of the supported markups and required libraries.

# Gemfile
gem "asciidoctor"
gem "radius"
gem "creole"
gem "tilt-handlebars"

# config/application.rb
config.angular_templates.markups.push 'asciidoc', 'radius', 'wiki', 'hbs'

If you would like to use a non-standard extension or you would like to use a custom template, you just need to tell Tilt about it.

# config/initializers/angular_rails_templates.rb
Tilt.register Tilt::HamlTemplate, 'nghaml'

# config/application.rb
config.angular_templates.markups.push 'nghaml'

Note: You would still need to use foo.html.nghaml

Configuration Option: extension

By default this gem looks only at templates with .html suffix, eg. foo.html or foo.html.haml. This extension allows you to change that to another extension

License

MIT License. Copyright 2017 pitr

Authors & contributors

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].