move sources to app directory
This commit is contained in:
15
app/class_view.rb
Normal file
15
app/class_view.rb
Normal file
@ -0,0 +1,15 @@
|
||||
class ClassView
|
||||
|
||||
include React::Component
|
||||
|
||||
required_param :sources, type: [Hash]
|
||||
|
||||
def render
|
||||
div class: "sourceList" do
|
||||
sources.each do |source|
|
||||
SourceView author: source[:author], text: source[:text]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
38
app/debugger.rb
Normal file
38
app/debugger.rb
Normal file
@ -0,0 +1,38 @@
|
||||
require 'opal'
|
||||
require 'browser'
|
||||
require 'opal-jquery'
|
||||
require "json"
|
||||
require 'opal-react'
|
||||
|
||||
require "class_view"
|
||||
require "register_view"
|
||||
require "source_view"
|
||||
|
||||
Document.ready? do # Document.ready? is a opal-jquery method.
|
||||
React.render( React.create_element( Debugger), Element['#content'] )
|
||||
end
|
||||
|
||||
class Debugger
|
||||
|
||||
include React::Component
|
||||
# required_param :url
|
||||
define_state sources: JSON.from_object(`window.initial_sources`)
|
||||
|
||||
# before_mount do
|
||||
# HTTP.get(url) do |response|
|
||||
# if response.ok?
|
||||
# sources! JSON.parse(response.body)
|
||||
# else
|
||||
# puts "failed with status #{response.status_code}"
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
|
||||
def render
|
||||
div class: "sourceBox" do
|
||||
h1 { "Sources" }
|
||||
ClassView sources: sources
|
||||
RegisterView submit_source: lambda { |source| sources! << sourceAuthor}
|
||||
end
|
||||
end
|
||||
end
|
27
app/register_view.rb
Normal file
27
app/register_view.rb
Normal file
@ -0,0 +1,27 @@
|
||||
class RegisterView
|
||||
|
||||
include React::Component
|
||||
required_param :submit_source, type: Proc
|
||||
|
||||
define_state :author, :text
|
||||
|
||||
def render
|
||||
div do
|
||||
div do
|
||||
"Author: ".span
|
||||
input(type: :text, value: author, placeholder: "Your name", style: {width: "30%"}).
|
||||
on(:change) { |e| author! e.target.value }
|
||||
end
|
||||
div do
|
||||
div(style: {float: :left, width: "50%"}) do
|
||||
textarea(value: text, placeholder: "Say something...", style: {width: "90%"}, rows: 10).
|
||||
on(:change) { |e| text! e.target.value }
|
||||
end
|
||||
div(style: {float: :left, width: "50%"}) do
|
||||
text
|
||||
end
|
||||
end
|
||||
button { "Post" }.on(:click) { submit_source :author => (author! ""), :text => (text! "") }
|
||||
end
|
||||
end
|
||||
end
|
17
app/source_view.rb
Normal file
17
app/source_view.rb
Normal file
@ -0,0 +1,17 @@
|
||||
class SourceView
|
||||
|
||||
include React::Component
|
||||
|
||||
required_param :author
|
||||
required_param :text
|
||||
|
||||
def render
|
||||
div class: "source" do
|
||||
h2(class: "sourceAuthor") { author }
|
||||
div do
|
||||
text
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
Reference in New Issue
Block a user