Skip to content

Commit c86dd96

Browse files
committed
Added new template
1 parent f9c4d00 commit c86dd96

File tree

9 files changed

+77
-8
lines changed

9 files changed

+77
-8
lines changed

lathe.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ require File.expand_path('../lib/lathe/version', __FILE__)
44
Gem::Specification.new do |gem|
55
gem.authors = ["vulgarcoder"]
66
gem.email = ["vulgarcoder@gmail.com"]
7-
gem.description = %q{Generator for plugin developer.}
7+
gem.description = %q{Generator for minxing365's plugin developer.}
88
gem.summary = %q{For minxing365.com}
99
gem.homepage = "https://github.com/vulgarcoder/lathe"
1010

Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
<div>
2+
<div class="title">标题:{title}</div>
3+
24
这是web的展示表单,位置在 app/templates/mini_apps/<%=app_name%>/show.js.dust
35
</div>
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
<div>
2+
<input autocomplete="off" class="title "
3+
name="<%=app_name%>" placeholder="请输入标题"
4+
type="text">
25
这是mobile的输入表单,位置在 app/templates/mobile/mini_apps/<%=app_name%>/new.js.dust
36
</div>
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
<div>
2+
<div>标题:{title}</div>
23
这是mobile的展示表单,位置在 app/templates/mobile/mini_apps/<%=app_name%>/new.js.dust
34
</div>

lib/lathe/generators/mini_app/app/assets/javascripts/%app_path%/app/views/mini_apps/%app_name%/new.js.tt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ jQuery(function($) {
99
return true;
1010
},
1111
getProperties: function() {
12+
var self=this;
1213
return{
13-
14+
title:this.$(".title").val()
1415
}
1516
//return json data
1617
}
Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,57 @@
1-
module <%=app_path.camelize%>
1+
module <%=package%>
22
class <%=app_class%> < MiniApp
33

4-
def build(story, user)
5-
4+
#处理miniapp创建的请求
5+
# * *Args* :
6+
# - +properties+ -> 客户端请求的参数,一个hash集合,形如:{title:"my Title"}
7+
# - +options+ -> 扩展参数
8+
def build(properties, options={})
9+
title = properties["title"]
10+
11+
model = <%=package%>::<%=app_class%>Model.create(:title=>title)
12+
13+
model.save!
14+
model
615
end
716

17+
#处理miniapp修改的请求
18+
# * *Args* :
19+
# - +instance+ -> <%=app_class%>Model实例
20+
# - +current_user+ -> 当前用户对象
21+
# - +http_action+ -> http请求类型,形如:get post put delete
22+
# - +proc_name+ -> 更新请求的函数名称,这个需要跟客户端进行约定,如 merge,update等
23+
# - +properties+ -> 客户端请求的参数,一个hash集合,形如:{title:"my Title"}
24+
#
25+
def call_service(instance,current_user, http_action, proc_name, properties)
26+
27+
end
28+
29+
#通过方法返回主对象
30+
# * *Args* :
31+
# - +id+ -> 对象主键id
32+
# * *Returns* :
33+
# - <%=app_class%>Model实例
34+
#
835
def find_instance_by_id(id)
9-
# MiniappStudy::QuestionModel.find_by_id id
36+
<%=package%>::<%=app_class%>Model.find_by_id id
37+
end
38+
39+
40+
#建立系统搜索用的索引
41+
def call_index(instance,options={})
42+
#package = {:object_id=>instance.id,:description=>instance.title,:created_at=>instance.created_at.to_i,:updated_at=>instance.updated_at.to_i}
43+
end
44+
#返回当前miniapp对应的json
45+
def dump_to_hash(instance)
46+
{}
1047
end
11-
48+
#如果当前miniapp的json中还有引用的对象,需要在此方法中进行填充,确保前端通过reference可以查询到这些引用对象
49+
#如
50+
def call_references(instance,keep_raw = true)
51+
result = []
52+
#result中存放reference对象,对象创建如:Reference.new(:user,u_id)
53+
#result.concat(instance.user_ids.map {|u_id| Reference.new(:user,u_id) })
54+
keep_raw ? result : result.uniq.compact
55+
end
1256
end
1357
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module <%=package%>
2+
class <%=app_class%>Model < ActiveRecord::Base
3+
include Cacheable
4+
5+
model_cache do
6+
with_attribute :id
7+
end
8+
end
9+
end
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Create<%=package%><%=app_class%>Models < ActiveRecord::Migration
2+
def change
3+
create_table :<%=app_path%>_<%=app_name%>_models do |t|
4+
t.string :title
5+
6+
t.timestamps
7+
end
8+
end
9+
end

lib/lathe/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module Lathe
2-
VERSION = "0.0.1"
2+
VERSION = "0.0.3"
33
end

0 commit comments

Comments
 (0)