havior 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +34 -0
- data/lib/generators/havior/USAGE +8 -0
- data/lib/generators/havior/havior_generator.rb +63 -0
- data/lib/generators/havior/install_generator.rb +32 -0
- data/lib/generators/havior/templates/haviors/controller.rb.erb +12 -0
- data/lib/generators/havior/templates/haviors/haxe/Havior.hx.erb +26 -0
- data/lib/generators/havior/templates/haviors/model.rb.erb +15 -0
- data/lib/generators/havior/templates/haviors/routes.rb.erb +7 -0
- data/lib/generators/havior/templates/haxe/havior.hxml.erb +7 -0
- data/lib/generators/havior/templates/haxe/lib/Havior.hx +83 -0
- data/lib/havior.rb +11 -0
- data/lib/havior/builder.rb +34 -0
- data/lib/havior/helper.rb +13 -0
- data/lib/havior/model.rb +33 -0
- data/lib/havior/routes.rb +12 -0
- data/lib/havior/version.rb +3 -0
- data/lib/tasks/havior_tasks.rake +4 -0
- data/test/dummy/Gemfile +46 -0
- data/test/dummy/Gemfile.lock +171 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/javascripts/application.js +16 -0
- data/test/dummy/app/assets/javascripts/top.coffee +3 -0
- data/test/dummy/app/assets/stylesheets/application.css +15 -0
- data/test/dummy/app/assets/stylesheets/top.scss +3 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/controllers/top_controller.rb +4 -0
- data/test/dummy/app/haviors/misc/todo/haxe/Todo.hx +42 -0
- data/test/dummy/app/haviors/misc/todo/model.rb +15 -0
- data/test/dummy/app/haviors/misc/todo/routes.rb +11 -0
- data/test/dummy/app/haviors/misc/todo/todo_controller.rb +24 -0
- data/test/dummy/app/haviors/misc/todo/views/todo.html.erb +1 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/helpers/top_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/app/views/top/index.html.erb +6 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +8 -0
- data/test/dummy/bin/rake +8 -0
- data/test/dummy/bin/setup +29 -0
- data/test/dummy/bin/spring +18 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +26 -0
- data/test/dummy/config/boot.rb +3 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +41 -0
- data/test/dummy/config/environments/production.rb +79 -0
- data/test/dummy/config/environments/test.rb +42 -0
- data/test/dummy/config/initializers/assets.rb +11 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +4 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +58 -0
- data/test/dummy/config/secrets.yml +22 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/seeds.rb +7 -0
- data/test/dummy/haxe/havior.hxml +7 -0
- data/test/dummy/haxe/lib/Havior.hx +83 -0
- data/test/dummy/log/development.log +96 -0
- data/test/dummy/public/404.html +67 -0
- data/test/dummy/public/422.html +67 -0
- data/test/dummy/public/500.html +66 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/public/javascripts/misc/todo/todo.js +206 -0
- data/test/dummy/public/robots.txt +5 -0
- data/test/dummy/public/stylesheets/misc/todo/todo.css +0 -0
- data/test/dummy/test/controllers/top_controller_test.rb +9 -0
- data/test/dummy/test/test_helper.rb +10 -0
- data/test/dummy/tmp/cache/assets/development/sass/f3ea2a11dd4dcf99bc71cead6095f5bcdec0e3c1/top.scssc +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/144480218666373c17378e01c880a73e +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/18d2cbb0f2269d20680f775d08981e72 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/34226a9205e8dd111f3fd667140e3557 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/55775c8c8fb4940e0575e4087043324a +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/69a055f006179beba2a830d88e39fa88 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/7c6e5314d519217e99ce56f93eacb7ca +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/82ac2910cee5ad83240253d81fd60ad8 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/86d34baf8dfb1e16ed00123e1e2a2190 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/9c1b6c9edc5c7d33d390964b955748a8 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/a69a6a0e8b2413a18e01dcc9e07b7263 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/ccf10475f5be0d54da1c2c223b3fca5d +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/cdf84c819e9ef95e6edb7a5d36549ca4 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/f4779bd843bfdc90d8c4fe47fcfc5c02 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/fe9f4bf7a4d033c8ec226c659ceba27e +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/ffa538b8e1d908ed228e70f373c3aa00 +0 -0
- data/test/dummy/tmp/pids/server.pid +1 -0
- data/test/havior_test.rb +7 -0
- data/test/test_helper.rb +18 -0
- metadata +255 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: edf5c6ade4789b66cdf8c6de4c05b62cfd098428
|
|
4
|
+
data.tar.gz: 149205eb40b8867e3f7e9b7ba82d986f6f656cc3
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: caed59d6bb1e7c7861d0de4f485aaac8ec9a88dc2cbd56dc04d9d2ca4da0f9b32768a45ab07b78e1ec46febe30f90915cb17b59ed405a28a274ba88dece19371
|
|
7
|
+
data.tar.gz: 9a4998b707489eeddc1eb38f09eec56e246ae6220b900a3fbe405e2efc81873ebdc20e503ee8be65a86527eabe7bedddf758999ed22117bb96fa0bf1c750b301
|
data/MIT-LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright 2015 Takeshi Kojima
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
begin
|
|
2
|
+
require 'bundler/setup'
|
|
3
|
+
rescue LoadError
|
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
require 'rdoc/task'
|
|
8
|
+
|
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
|
11
|
+
rdoc.title = 'Havior'
|
|
12
|
+
rdoc.options << '--line-numbers'
|
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
Bundler::GemHelper.install_tasks
|
|
23
|
+
|
|
24
|
+
require 'rake/testtask'
|
|
25
|
+
|
|
26
|
+
Rake::TestTask.new(:test) do |t|
|
|
27
|
+
t.libs << 'lib'
|
|
28
|
+
t.libs << 'test'
|
|
29
|
+
t.pattern = 'test/**/*_test.rb'
|
|
30
|
+
t.verbose = false
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
task default: :test
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
module Havior
|
|
2
|
+
module Generators
|
|
3
|
+
class HaviorGenerator < Rails::Generators::NamedBase
|
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
|
5
|
+
|
|
6
|
+
def build_variables
|
|
7
|
+
|
|
8
|
+
puts @hxml_path = "haxe/havior.hxml"
|
|
9
|
+
puts @file_path = file_path
|
|
10
|
+
puts @file_name = file_name
|
|
11
|
+
puts @module_name = class_name
|
|
12
|
+
puts @class_name = class_name.split("::").last
|
|
13
|
+
puts @js_path = "javascripts/#{file_path}/#{file_name}.js"
|
|
14
|
+
puts @css_path = "stylesheets/#{file_path}/#{file_name}.css"
|
|
15
|
+
puts @haxe_class_full_name = file_path.camelize.gsub("::",".")
|
|
16
|
+
puts @haxe_class_name = file_name.camelize
|
|
17
|
+
puts @havior_root = "app/haviors/#{file_path}"
|
|
18
|
+
puts @haxe_dir = "#{@havior_root}/haxe"
|
|
19
|
+
puts @haxe_path = "#{@havior_root}/haxe/#{@haxe_class_name}.hx"
|
|
20
|
+
puts @view_name = "#{file_name}.html.erb"
|
|
21
|
+
puts @view_dir = "#{@havior_root}/views"
|
|
22
|
+
puts @view_path = "#{@view_dir}/#{@view_name}"
|
|
23
|
+
puts @actions = args.map{|arg|arg.split(":")}.map{|k,v| [k, v||"get"] }
|
|
24
|
+
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
@@compiled_erb = ->(script, binding){
|
|
28
|
+
file = File.expand_path("../templates/#{script}",__FILE__)
|
|
29
|
+
erb = ERB.new(open(file).read)
|
|
30
|
+
erb.result(binding)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
def create_empty_js_css
|
|
34
|
+
create_file "public/#{@js_path}", ""
|
|
35
|
+
create_file "public/#{@css_path}", ""
|
|
36
|
+
end
|
|
37
|
+
def append_hxml
|
|
38
|
+
append_to_file @hxml_path,
|
|
39
|
+
@@compiled_erb.call("haxe/havior.hxml.erb", binding)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def create_dummy_view
|
|
43
|
+
create_file @view_path, "##{@class_name}"
|
|
44
|
+
end
|
|
45
|
+
def create_haxe
|
|
46
|
+
create_file @haxe_path,
|
|
47
|
+
@@compiled_erb.call("haviors/haxe/Havior.hx.erb", binding)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def create_rubies
|
|
51
|
+
create_file "#{@havior_root}/model.rb",
|
|
52
|
+
@@compiled_erb.call("haviors/model.rb.erb", binding)
|
|
53
|
+
|
|
54
|
+
create_file "#{@havior_root}/#{@file_name}_controller.rb",
|
|
55
|
+
@@compiled_erb.call("haviors/controller.rb.erb", binding)
|
|
56
|
+
|
|
57
|
+
create_file "#{@havior_root}/routes.rb",
|
|
58
|
+
@@compiled_erb.call("haviors/routes.rb.erb", binding)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
module Havior
|
|
2
|
+
module Generators
|
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
|
4
|
+
|
|
5
|
+
source_root File.expand_path('../templates', __FILE__)
|
|
6
|
+
|
|
7
|
+
def create_haxe_hxml
|
|
8
|
+
create_file "haxe/havior.hxml", ""
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def copy_haxe_libs
|
|
12
|
+
copy_file "haxe/lib/Havior.hx", "haxe/lib/Havior.hx"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def inject_havior_helper
|
|
16
|
+
inject_into_file "app/helpers/application_helper.rb",
|
|
17
|
+
after: "module ApplicationHelper\n"do
|
|
18
|
+
" include Havior::Helper\n"
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def inject_routes
|
|
23
|
+
inject_into_file "config/routes.rb",
|
|
24
|
+
after: "Rails.application.routes.draw do\n" do
|
|
25
|
+
" Havior::Routes.load\n"
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
class <%= @module_name %>::<%= @class_name %>Controller < ApplicationController
|
|
2
|
+
|
|
3
|
+
<% @actions.each do |name,method| %>
|
|
4
|
+
# <%= method.upcase %> /havior/<%= @file_path %>/<%= @file_name %>/<%= name %>
|
|
5
|
+
def <%= name %>
|
|
6
|
+
render json: { result: "success",
|
|
7
|
+
message: "`<%= @module_name %>::<%= @class_name %>#<%= name %>`" }
|
|
8
|
+
end
|
|
9
|
+
<% end %>
|
|
10
|
+
|
|
11
|
+
end
|
|
12
|
+
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import jQuery.*;
|
|
2
|
+
|
|
3
|
+
class <%= @haxe_class_name %> extends Havior {
|
|
4
|
+
public static function main(){
|
|
5
|
+
Havior.start("<%= @file_path %>");
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
public override function onLoad(){
|
|
9
|
+
|
|
10
|
+
<% @actions.each do |name,method| %>
|
|
11
|
+
// <%= route = "#{name}@#{method}" %>
|
|
12
|
+
addCallback("<%= route %>", function(data){
|
|
13
|
+
/// TODO
|
|
14
|
+
this.getDOM().html("<%= route%>:" + data.message);
|
|
15
|
+
});
|
|
16
|
+
<% end %>
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
<% @actions.each do |name,method| %>
|
|
20
|
+
// sendAsync("<%= "#{name}@#{method}" %>", {} );
|
|
21
|
+
<% end %>
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import jQuery.*;
|
|
2
|
+
|
|
3
|
+
typedef AsyncCallback = Dynamic -> Void
|
|
4
|
+
|
|
5
|
+
class Havior {
|
|
6
|
+
public static var com_name : String;
|
|
7
|
+
|
|
8
|
+
public static function start(name, ?pos:haxe.PosInfos){
|
|
9
|
+
com_name = name;
|
|
10
|
+
var klass = Type.resolveClass(pos.className);
|
|
11
|
+
var class_name = StringTools.replace(name, "/", "-");
|
|
12
|
+
var coms = new JQuery(".havior-"+class_name);
|
|
13
|
+
for(com in coms){
|
|
14
|
+
var id = new JQuery(com).attr("id");
|
|
15
|
+
var c = Type.createInstance(klass, [id]);
|
|
16
|
+
c.onLoad();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public function onLoad(){}
|
|
21
|
+
|
|
22
|
+
private var id : String;
|
|
23
|
+
private var dom : JQuery;
|
|
24
|
+
private var callbacks = new Map<String, Array<AsyncCallback>>();
|
|
25
|
+
|
|
26
|
+
public function new(id : String){
|
|
27
|
+
this.id = id;
|
|
28
|
+
this.dom = new JQuery("#"+id);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public function getId(){ return this.id;}
|
|
32
|
+
public function getDOM(){ return this.dom; }
|
|
33
|
+
|
|
34
|
+
public function addCallback(route:String, func:AsyncCallback){
|
|
35
|
+
if(!this.callbacks.exists(route)){
|
|
36
|
+
this.callbacks.set(route, new Array<AsyncCallback>());
|
|
37
|
+
}
|
|
38
|
+
this.callbacks.get(route).push(func);
|
|
39
|
+
}
|
|
40
|
+
private function callCallback(route:String, data:Dynamic){
|
|
41
|
+
if(this.callbacks.exists(route)){
|
|
42
|
+
for(func in this.callbacks.get(route)){
|
|
43
|
+
func(data);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public function children(selector){
|
|
49
|
+
return new JQuery("#"+getId()+" ,#"+getId()+" *").children(selector);
|
|
50
|
+
}
|
|
51
|
+
public function getParams(){
|
|
52
|
+
return getDOM().data();
|
|
53
|
+
}
|
|
54
|
+
public function getParam(name:String){
|
|
55
|
+
return Reflect.field(getParams(), name);
|
|
56
|
+
}
|
|
57
|
+
public function getParamNames(){
|
|
58
|
+
return Reflect.fields(getParams);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
public function sendAsync(route:String, params:Dynamic){
|
|
63
|
+
var xs = route.split("@");
|
|
64
|
+
var action = xs[0];
|
|
65
|
+
var method = xs[1];
|
|
66
|
+
var url = "/havior/"+ com_name +"/"+ action;
|
|
67
|
+
var callback = function(data,status,xhr){
|
|
68
|
+
callCallback(route, data);
|
|
69
|
+
}
|
|
70
|
+
var query = switch(method){
|
|
71
|
+
case "get":
|
|
72
|
+
JQueryStatic.get(url, params, callback);
|
|
73
|
+
case "post", _:
|
|
74
|
+
JQueryStatic.post(url, params, callback);
|
|
75
|
+
}
|
|
76
|
+
query.fail(function(e){
|
|
77
|
+
trace("ERROR:"+e);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
data/lib/havior.rb
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
module Havior
|
|
2
|
+
class Builder
|
|
3
|
+
|
|
4
|
+
def initialize
|
|
5
|
+
@count = 0
|
|
6
|
+
@components = []
|
|
7
|
+
end
|
|
8
|
+
def destribute name, ajax_params = {}, erb_params={}
|
|
9
|
+
namespace = name.to_s.camelize
|
|
10
|
+
@count += 1
|
|
11
|
+
klass = Module.const_get("#{namespace}::Model")
|
|
12
|
+
obj = klass.new @count
|
|
13
|
+
@components.push obj
|
|
14
|
+
obj.html(ajax_params, erb_params).html_safe
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def all_javascripts
|
|
18
|
+
@components.inject([]){|acc,c|acc + c.javascripts}.uniq
|
|
19
|
+
end
|
|
20
|
+
def all_stylesheets
|
|
21
|
+
@components.inject([]){|acc,c|acc + c.stylesheets}.uniq
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def refer_to_javascripts
|
|
25
|
+
all_javascripts.map{|js|
|
|
26
|
+
"<script type='text/javascript' src='#{js}'></script>" }.join
|
|
27
|
+
end
|
|
28
|
+
def refer_to_stylesheets
|
|
29
|
+
all_stylesheets.map{|css|
|
|
30
|
+
"<link rel='stylesheet' type='text/css' href='#{css}'>" }.join
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
end
|
|
34
|
+
end
|
data/lib/havior/model.rb
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
module Havior
|
|
2
|
+
class Model
|
|
3
|
+
attr_reader :html_identifier, :html_classes
|
|
4
|
+
def initialize id
|
|
5
|
+
prefix = "havior"
|
|
6
|
+
components = self.class.name.underscore.split("/")[0..-2]
|
|
7
|
+
@dir = components.join("/")
|
|
8
|
+
html_class_name = prefix + "-" + components.join("-")
|
|
9
|
+
@html_identifier = "#{html_class_name}-#{id}"
|
|
10
|
+
@html_classes = ["havior", html_class_name]
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def javascripts
|
|
14
|
+
[]
|
|
15
|
+
end
|
|
16
|
+
def stylesheets
|
|
17
|
+
[]
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def html ajax_params={}, erb_params={}
|
|
21
|
+
action_view = ActionView::Base.new "#{Rails.root}/app/haviors/#{@dir}/views"
|
|
22
|
+
erb_params.each{|k,v| action_view.assign(k=>v) }
|
|
23
|
+
ajax_params.each{|k,v| action_view.assign(k=>v) }
|
|
24
|
+
data = ajax_params.map{|k,v| "data-#{k}='#{v}'" }.join(' ')
|
|
25
|
+
return <<HTML
|
|
26
|
+
<div id="#{@html_identifier}" class="#{@html_classes.join(' ')}" #{data}>
|
|
27
|
+
#{action_view.render(template: self.erb_script)}
|
|
28
|
+
</div>
|
|
29
|
+
HTML
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
end
|
|
33
|
+
end
|