Giter VIP home page Giter VIP logo

Codus

Tools to improve your life as Rails developer.

Javascript Organizer

You can write your javascript functions using yojs namespaces declaration. Namespaces that matches your application name, current controller and current action will automatic be fired.

Setup

  • Put in your Gemfile:
gem 'codus'
  • Install the gem with bundle install

  • Put in your layout:

<%= load_yojs(:app_name => 'yourappname') %>

  • Put in your application.js
//= require jquery
//= require yojs
  • Declare your functions using yojs and enjoy your life

Options

app_name

The load_yojs helper method will print a javascript code, using query and yojs, that calls namespaces matching the app_name option, current controller name and current action name.

For instance, if you're in /posts/new it will call:

  1. yourappname

  2. yourappname.posts

  3. yourappname.posts.new

onload_method_name

You can set the name of the last namespace to be called on the unload event with the onload_method_name option. For instance:

<%= load_yojs(:app_name => 'yourappname', :onload_method_name => "myonloadmethod") %>

If you're in /posts/new it will call:

  1. yourappname.

  2. yourappname.posts.

  3. yourappname.posts.new.

method_names_mapper

You can also configure equivalent namespaces using :<method_names_mapper. For instance:>

<%= load_yojs(:app_name => 'yourappname', 

                     :method_names_mapper => {

                                  :create => :new,

                                  :update => :edit

                                }

                    )%>

If you're in /posts/create it will call:

  1. yourappname

  2. yourappname.posts

  3. yourappname.posts.create

  4. yourappname.posts.new

File structure

We recomend you to structure your js files according your namespace hierarchy. Example

- assets
  |- javascripts 
     |- application.js
     |- components (jquery, plugins, etc)
     |- myapp
     |  |- myapp.js (global javascripts in "myapp" namespace)
     |  |- controller1
     |  |  |- controller1.js (javascripts shared between "myapp.controller1" namespace)
     |  |  |- action1.js (javascripts for "myapp.controller1.action1" namespace)
     |  |  |- action2.js (javascripts for "myapp.controller1.action2" namespace)
     |  |  |- actionN.js (javascripts for "myapp.controller1.actionN" namespace)
     |  |  
     |  |- controller2
     |  |  |- controller2.js (javascripts shared between "myapp.controller2" namespace)
     |  |  |- action1.js (javascripts for "myapp.controller2.action1" namespace)
     |  |  |- action2.js (javascripts for "myapp.controller2.action2" namespace)
     |  |  |- actionN.js (javascripts for "myapp.controller2.actionN" namespace)
     |  |  
     |  |- controllerN
     |  |  |- controllerN.js (javascripts shared between "myapp.controllerN" namespace)
     |  |  |- ...

Codus Tecnologia's Projects

codelog icon codelog

A simple ruby gem to manage Changelogs.

codus icon codus

Organize your javascript across namespaces matching your controllers and actions. Get automatic executing functions for current controller and action.

yojs icon yojs

Javascript library for declaring and calling functions and variables using namespaces.

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.