Project

magicka

0.0
Low commit activity in last 3 years
No release in over a year
Gem for easy form templating
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 2.3.25
= 0.12.2
= 0.3.0
= 13.0.1
= 6.0.3
= 3.9.0
= 3.9.3
= 0.80.1
= 0.17.1
= 1.4.2
= 0.9.9
= 7.0.4.3
= 7.0.4.3
= 1.12.5
= 7.0.4.3
= 4.6.1
= 0.9.26
~> 1.2022.1

Runtime

>= 2.0.1
 Project Readme

Magicka

Code Climate Test Coverage Issue Count Gem Version Codacy Badge Inline docs

magicka

Magica helps creating html templates for forms and display data using js applications such as AngulaJS

Current Release: 1.1.0

Next release

Yard Documentation

https://www.rubydoc.info/gems/magicka/1.1.0

Installation

  • Install it
  gem install magicka
  • Or add Magicka to your Gemfile and bundle install:
  gem 'magicka'
  bundle install magicka

Usage

Magicka is used as a helper for erb coding so that each element is paired with an element class, a template and a method in an aggregator.

Different aggregators have the same method so that they render the same element in different ways

example

<!-- new.html.erb -->

<% magicka_form('controller.person') do |form| %>
  <%= render partial: 'person_form', locals: { form: form } %>
<% end %>
<!-- show.html.erb -->

<% magicka_display('controller.person') do |form| %>
  <%= render partial: 'person_form', locals: { form: form } %>
<% end %>
<!-- _person_form.html.erb -->

<%= form.input(:first_name) %>
<%= form.input(:last_name) %>
<%= form.input(:age) %>
<%= form.select(:gender, options: %w[MALE FEMALE] %>

<%= form.only(:form) do %>
  <!-- this block only appears in a form -->
  <%= form.button(ng_click: 'controller.save', text: 'Save') %>
<% end %>

Configuring

In order to use magicka, the helper has to added to the controllers and any custom element needs to added

app/controllers/application_controller.rb

class ApplicationController < ActionController::Base
  helper Magicka::Helper
end

Including custom elements

Elements can be included by defining attributes that they can be initialized with and that can be passed to the template

config/initializers/magicka.rb

module Magicka
  class MyTextInput < Magicka::Element
    with_attribute_locals :label, :field, :id
  end
end

Magicka::Form.with_element(Magicka::MyTextInput)

templates/form/_my_text_input.html.erb

<div>
  <label for="<%= field %>"><%= label %></label>
  <input type="text" id="<%= id %>" name="field" />
</div>