All Projects → merongivian → vue.rb

merongivian / vue.rb

Licence: other
Ruby bindings for Vue.js

Programming Languages

ruby
36898 projects - #4 most used programming language
shell
77523 projects

Labels

Projects that are alternatives of or similar to vue.rb

opal-node-compiler
Opal Compiler for Node.js
Stars: ✭ 15 (-42.31%)
Mutual labels:  opal
opal-rspec
Opal + RSpec = ♥️
Stars: ✭ 57 (+119.23%)
Mutual labels:  opal
opal-haml
Opal + Haml = <3
Stars: ✭ 20 (-23.08%)
Mutual labels:  opal
glimmer-dsl-opal
Glimmer DSL for Opal (Pure-Ruby Web GUI and Auto-Webifier of Desktop Apps)
Stars: ✭ 22 (-15.38%)
Mutual labels:  opal
Opal
Ruby ♥︎ JavaScript
Stars: ✭ 4,552 (+17407.69%)
Mutual labels:  opal
sedcli
sedcli and libsed library for NVMe Self-Encrypting Drives (SEDs) management
Stars: ✭ 22 (-15.38%)
Mutual labels:  opal
opal
Policy and data administration, distribution, and real-time updates on top of Open Policy Agent
Stars: ✭ 459 (+1665.38%)
Mutual labels:  opal
op-test
Testing Firmware for OpenPOWER systems
Stars: ✭ 30 (+15.38%)
Mutual labels:  opal
negasonic
This ain't Sonic Pi, but it works on the browser: www.negasonic.org
Stars: ✭ 73 (+180.77%)
Mutual labels:  opal
snabberb
A simple component view framework for Ruby Opal based on Snabbdom
Stars: ✭ 41 (+57.69%)
Mutual labels:  opal

Vue.rb

Lets you write Vue.js code in Ruby!!!

class ReverseMessage < Vue
  data :message, "Reverse this message"

  def reverse_message
    self.message = message.reverse
  end
end

ReverseMessage.new('#app')
<div id="app">
  <p>{{ message }}</p>
  <button v-on:click="reverse_message">Reverse Message</button>
</div>

Installation (Ruby on Rails)

Install vue.js through yarn

$ yarn add vue

Add the following gems in your Gemfile

  gem 'opal-rails'
  gem 'vue.rb', git: 'https://github.com/merongivian/vue.rb'

and run bundle exec install

Require both Javascript and Ruby files in application.js.rb

# Javascript to Ruby compiler
require 'opal'

# require javascript before ruby code
require 'vue/dist/vue.js'
require 'vue.rb'

Adding Vue code

Make sure your vue code loads after the page is loaded

# config/initializers/assets.rb

Rails.application.config.assets.precompile += %w(my_vue_code.js.rb) # should be in app/assets/javascripts
<!-- application.html.erb -->

<!DOCTYPE html>
<html>
  <head>...</head>

  <body>
    <%= yield %>
  </body>

  <%= javascript_include_tag 'my_vue_code' %>
</html>

More examples

check the examples section

Credits

This code is mostly a copy of arika's example. I just merely refactor it a bit and put it into a gem 😊

Contributing

This is not a complete implementation of the API, so if something is missing please do help with PR's

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].