Skip to content

holderbaum/wormhole

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

215 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Wormhole is a simple concept, to provide a solution for getting configuration and runtime objects in a clean way from the rails-server-side into the javascript-client-side.

The Wormhole-object can contain several namespaces. Every namespace represents a configuration-object:

Wormhole.create(:my_namespace) do |c|
  # c is a config-object
  c.key_1 = "value"
  c.key_2 = 42
end

or:

c = Wormhole.create(:my_other_namespace)
c.key_1 = "value"
c.key_2 = 42

These initial namespace creations could be placed in the environment.rb or in another, perhaps self created file, that gets sourced by the rails-server on bootup.

Now, in every view, you can simply call:

<script><%= Wormhole.to_javascript %></script>

This will create the sourcecode for a javascript-object. In case of our two namespaces, the object would be used as followed:

<script>
  Wormhole.my_namespace.key_2 // returns 42
  Wormhole.my_other_namespace.key_1 // returns "value"
</script>

Beside this initial configuration, every namespace can be accessed and edited on a per-request and non-persistant way:

# in an action
Wormhole(:my_namespace) do |c|
  c.key_2 = 43
end

or:

c = Wormhole(:my_namespace)
c.key_2 = 43

In the correspondingly view, key_2 will now return the new value. But this change is not permanent, the underlying namespace is never mutable.

will follow..

rake gem
gem install bundler
bundle install
rake
  • build doc

    rake yard
    
  • then open file:///path/to/gem/doc/index.html in your browser

  • Seed Wormhole::Config with (nested) values:

    Wormhole::Config.new(:key => { :subkey => :value })
    

About

[archived] Imagine a world, with wormholes between the rails-o-verse and the javascript-o-verse

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors