All Projects → clearwater-rb → Clearwater

clearwater-rb / Clearwater

Licence: mit
Component-based Ruby front-end framework

Programming Languages

ruby
36898 projects - #4 most used programming language

Labels

Projects that are alternatives of or similar to Clearwater

Learning Roadmap
The Front-End Developer Learning Roadmap by Frontend Masters
Stars: ✭ 336 (-43.05%)
Mutual labels:  front-end
Reactjs101
從零開始學 ReactJS(ReactJS 101)是一本希望讓初學者一看就懂的 React 中文入門教學書,由淺入深學習 ReactJS 生態系 (Flux, Redux, React Router, ImmutableJS, React Native, Relay/GraphQL etc.)。
Stars: ✭ 4,004 (+578.64%)
Mutual labels:  front-end
Vue Boilerplate Template
🍎 Efficient development of web SPA using Vue.js(2.*) + Webpack + Element-ui + Pwa + Vuex + Vuex-router + Vue-i18n + Dayjs + Lodash.
Stars: ✭ 461 (-21.86%)
Mutual labels:  front-end
Mosaic
🎨 A front-end JavaScript library for building user interfaces!
Stars: ✭ 390 (-33.9%)
Mutual labels:  front-end
Front End Handbook 2019
[Book] 2019 edition of our front-end development handbook
Stars: ✭ 3,964 (+571.86%)
Mutual labels:  front-end
Front End Rss
📙 根据 RSS 抓取最新前端技术文章,来源:前端早读课、前端大全、前端之巅、淘宝前端、张鑫旭博客、凹凸实验室等
Stars: ✭ 418 (-29.15%)
Mutual labels:  front-end
Cs Wiki
🎉 致力打造完善的 Java 后端知识体系,不仅仅帮助各位小伙伴快速且系统的准备面试,更指引学习的方向
Stars: ✭ 369 (-37.46%)
Mutual labels:  front-end
Social Share Button
Helper for add social share feature in your Rails app. Twitter, Facebook, Weibo, Douban ...
Stars: ✭ 567 (-3.9%)
Mutual labels:  front-end
Sku
Front-end development toolkit
Stars: ✭ 403 (-31.69%)
Mutual labels:  front-end
Dragula
👌 Drag and drop so simple it hurts
Stars: ✭ 21,011 (+3461.19%)
Mutual labels:  front-end
Company Box
A company front-end with icons
Stars: ✭ 395 (-33.05%)
Mutual labels:  front-end
Playroom
Design with JSX, powered by your own component library.
Stars: ✭ 4,033 (+583.56%)
Mutual labels:  front-end
Beautiful React Hooks
🔥 A collection of beautiful and (hopefully) useful React hooks to speed-up your components and hooks development 🔥
Stars: ✭ 5,242 (+788.47%)
Mutual labels:  front-end
Libreddit
Private front-end for Reddit written in Rust
Stars: ✭ 387 (-34.41%)
Mutual labels:  front-end
Intercooler Js
Making AJAX as easy as anchor tags
Stars: ✭ 4,662 (+690.17%)
Mutual labels:  front-end
Front End Doc
前端文档汇总(觉得对您有用的话,别忘了star收藏哦^_^ !)
Stars: ✭ 372 (-36.95%)
Mutual labels:  front-end
Frontend Feed
🇧🇷 Lista de blogs e sites úteis para frontenders
Stars: ✭ 416 (-29.49%)
Mutual labels:  front-end
Displayjs
A simple JavaScript framework for building ambitious UIs 😊
Stars: ✭ 590 (+0%)
Mutual labels:  front-end
Blog
😛 个人博客 🤐 订阅是 watch 是 watch 是 watch 是 watch
Stars: ✭ 555 (-5.93%)
Mutual labels:  front-end
Front End Handbook 2018
2018 edition of our front-end development handbook
Stars: ✭ 4,172 (+607.12%)
Mutual labels:  front-end

clearwater

Join Chat Quality Build Downloads Issues License Version

Clearwater is a rich front-end framework for building fast, reasonable, and easily composable browser applications in Ruby. It renders to a virtual DOM and applies the virtual DOM to the browser's actual DOM to update only what has changed on the page.

Installing

Add these lines to your application's Gemfile:

gem 'clearwater'
gem 'opal-rails' # Only if you're using Rails

Using

This is a minimum-viable Clearwater app:

require 'opal'
require 'clearwater'

class HelloWorld
  include Clearwater::Component
  
  def render
    h1('Hello, world!')
  end
end

app = Clearwater::Application.new(component: HelloWorld.new)
app.call

Clearwater has three distinct parts:

  1. The component: the presenter and template engine
  2. The router (optional): the dispatcher and control
  3. The application: the "Go" button

The Component

class Blog
  # All components need a set of behavior, but don't worry it's not a massive list.
  include Clearwater::Component

  # This method needs to return a virtual-DOM element using the element DSL.
  # The DSL is provided by the Clearwater::Component mixin.
  def render
    div([
      Articles.new,
      Biography.new,
    ])
  end
end

While we use two components in this example, you can use all of these as well:

# <div id="foo">
#   <h1>Heading</h1>
#   <article>hello!</article>
# </div>
def render
  div({ id: 'foo' }, [
    h1('Heading'),
    article('hello!'),
  ])
end

# <div>Hello, world!</div>
def render
  div('Hello, world!')
end

# <div>123</div>
def render
  div(123)
end

# <div></div>
def render
  div
end

The Router

router = Clearwater::Router.new do
  # A route with a block contains subordinate routes
  route 'blog' => Blog.new do # /blog
    route 'new_article' => NewArticle.new # /blog/new_article

    # This path contains a dynamic segment. Inside this component, you can use
    # router.params[:article_id] to return the value for this segment of the
    # URL. So for "/articles/123", router.params[:article_id] would be "123".
    route ':article_id' => ArticleReader.new # /blog/123
  end
end

Using with Rails

You can also use Clearwater as part of the Rails asset pipeline. First create your Clearwater application (replace app/assets/javascripts/application.js with this file):

app/assets/javascripts/application.rb

require 'opal' # Not necessary if you load Opal from a CDN
require 'clearwater'

class Layout
  include Clearwater::Component

  def render
    h1('Hello, world!')
  end
end

app = Clearwater::Application.new(component: Layout.new)
app.call

app/views/layouts/application.html.erb

<!DOCTYPE html>
<html>
  <!-- snip -->

  <body>
    <!--
      We load the JS in the body tag to ensure the element exists so we can
      render to it. Otherwise, we need to use events on the document before we
      instantiate and call the Clearwater app. And that's no fun.
    -->
    <%= javascript_include_tag 'application' %>
  </body>
</html>

Then you need to get Rails to render a blank page, so add these two routes:

config/routes.rb

root 'home#index'
get '*all' => 'home#index'

You can omit the second line if your Clearwater app doesn't use routing. It just tells Rails to let your Clearwater app handle all routes.

app/controllers/home_controller.rb

class HomeController < ApplicationController
  def index
  end
end

app/views/home/index.html.erb

<!-- This page intentionally left blank -->

You can use the Rails generators to generate the controller and view (rails g controller home index), but it won't set up the root and catch-all routes, so you'll still need to do that manually.

Once you've added those files, refresh the page. You should see "Hello, world!" in big, bold letters. Congrats! You've built your first Clearwater app on Rails!

Using with Roda

If you're using Roda, you'll want to use the roda-opal_assets gem to get an asset-pipeline-style workflow for compiling your Clearwater app into JavaScript.

Getting Started

Use the clearwater-roda gem to generate a starter Clearwater app that demonstrates many components working together, routing, and even state management (via grand_central).

Experiment!

You can experiment with Clearwater using the Clearwater Playground. You can also explore other saved playground experiments.

Contributing

This project is governed by a Code of Conduct

  1. Fork it
  2. Branch it
  3. Hack it
  4. Save it
  5. Commit it
  6. Push it
  7. Pull-request it

License

Copyright (c) 2014-2018 Jamie Gaskins

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

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