ua 0.0.1 → 0.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9ad74d1d330de313f95145bd83628fdae497dcef
4
- data.tar.gz: 7fd313863434a180a407a0067131aaf1a651d12a
3
+ metadata.gz: 11625f1fbb808f1144ac4f61c24e2fd6da09b29c
4
+ data.tar.gz: 9001f6348093b921b3b49d23752beb2ae2c38376
5
5
  SHA512:
6
- metadata.gz: b8f9e8d56f4ff269efe5afe162c5625c536c11dd78e46a1168a5e5b20759ab44f5ab545ea0dcf7cbdb89918cca778fbe8da9ac750f76ecc42dd3c3bb3792b26f
7
- data.tar.gz: d62728ea0618ec07bba824fda8264161a96330e90ce582a232cbff769061242bf423087938edb1245a2135a43f65ec2f20798b4a1f39ef88f8a80153e908ea8a
6
+ metadata.gz: 16985d539c4a6394e5c7cfba989163a62f53581d0e29d3fa33d0d55bfa281cf103c5221da7d005c0889572873db48fe5c70787e2d84d15d8bbe52d8b0afe7a22
7
+ data.tar.gz: 3739af37d2b7603028b9cc5412b962710848dee76135833ff0b7237044e93445cbb4699e9ff02ba7436f21985d0194bc9b6acbe7ced32df2823a9ed6981c369b
@@ -0,0 +1,79 @@
1
+ module Ua
2
+ module Util
3
+ class Helper
4
+ def initialize(obj)
5
+ @obj = obj
6
+ end
7
+
8
+ def [](*args)
9
+ if args.size == 1
10
+ @obj[args[0]]
11
+ else
12
+ args.map{|x| @obj[x]}
13
+ end
14
+ end
15
+
16
+ alias values_at []
17
+
18
+
19
+ def []=(*args)
20
+ last = args.pop(1)
21
+ args.zip(last).each{|k|
22
+ a,b = k
23
+ @obj[a] = b
24
+ }
25
+ end
26
+
27
+ def define_context(name, &block)
28
+ app = Ua::Application.top.app
29
+ app.context @obj.prototype, name, &block
30
+ end
31
+
32
+ def app
33
+ render :app
34
+ end
35
+
36
+ def render(ctxt = Ua::Application.top.context)
37
+ context(@obj, ctxt)
38
+ end
39
+ end
40
+ def ua(obj_or_str)
41
+ if Ua::Application::UAClass === obj_or_str
42
+ return Helper.new(obj_or_str)
43
+ elsif String === obj_or_str
44
+ return Helper.new(Ua::Application.top_app.get(obj_or_str))
45
+ end
46
+ raise ArgumentError, "Don't know how to make ua from #{obj_or_str}", caller(3)
47
+ end
48
+
49
+
50
+ class AppHelper
51
+ def initialize(app = Ua::Application.top_app)
52
+ @app = app
53
+ end
54
+ def push
55
+ Ua::Application.push_app @app
56
+ end
57
+ def define_command(name, id, *names, &bl)
58
+ bl ||= lambda{|a| a}
59
+ uaobject = Helper.new @app.get id
60
+ (class << self; self; end).send :define_method, name do |*args|
61
+ uaobject[*names] = args
62
+ bl.call(context(uaobject, :app))
63
+ end
64
+ end
65
+ def pop
66
+ Ua::Application.pop_app if Ua::Application.top_app == @app
67
+ end
68
+ end
69
+
70
+ def uapp(app = Ua::Application.top_app)
71
+ AppHelper.new(app)
72
+ end
73
+
74
+ def istr(str)
75
+ first = str[/^\s*(\S)/, 1]
76
+ str.split("\n").map{|x| x.sub(/^\s*#{Regexp.escape(first)}/, "")}.join("\n")
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,37 @@
1
+ module Ua
2
+ module Util
3
+ class Helper
4
+ def initialize(obj)
5
+ @obj = obj
6
+ end
7
+
8
+ def [](*args)
9
+ if args.size == 1
10
+ obj[args[0]]
11
+ else
12
+ args.map{|x| obj[x]}
13
+ end
14
+ end
15
+
16
+ alias values_at []
17
+
18
+ def []=(*args)
19
+ last = args.pop
20
+ args.zip(last).each{|k|
21
+ a,b = k
22
+ @obj[a] = b
23
+ }
24
+ end
25
+
26
+
27
+ end
28
+ def ua(obj_or_str)
29
+ if Ua::UAClass === obj_or_str
30
+ return Helper.new(obj_or_str)
31
+ elsif String === obj_or_str
32
+ return Helper.new(Ua::Application.top_app.get(obj_or_str))
33
+ end
34
+ raise "Don't know how to make ua from #{obj_or_str}"
35
+ end
36
+ end
37
+ end
@@ -1,3 +1,3 @@
1
1
  module Ua
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,15 @@
1
+ $: << "../lib"
2
+ require 'ua'
3
+
4
+
5
+
6
+ context Symbol, :mycontext do |sym|
7
+ puts sym.to_s * 3
8
+ sym.to_s
9
+ end
10
+
11
+ u = ua add 'test.context'
12
+ u.define_context(:mycontext) do |u| context(u.a) end
13
+ u[:a] = :Hello
14
+ puts u.render(:mycontext1)
15
+
@@ -0,0 +1,165 @@
1
+ $: << "../lib"
2
+ require 'ua'
3
+ link 'com.ua.root', 'html'
4
+ model 'html' do
5
+ %{
6
+ <!doctype html>
7
+ <html>
8
+ <head>
9
+ <title> <%= title || "Hello" %> </title>
10
+ </head>
11
+ <body>
12
+ <%= context get 'elements' %>
13
+
14
+ <script>
15
+ $scope = {}
16
+ $views = {}
17
+ window.update = function(a){
18
+ $views[a].forEach(function(f, i){
19
+ f.update();
20
+ })
21
+ }
22
+ <%= context get 'jsevent' %>
23
+ <%= context get 'jsinit' %>
24
+ <%= context get 'jsload' %>
25
+ </script>
26
+ </body>
27
+ }
28
+ end
29
+ model 'jsevent'
30
+ model 'jsinit'
31
+ model 'jsload'
32
+ model 'elements'
33
+ view String, :attrval do |str| str.inspect end
34
+ view String, :jsstr do |str| str.inspect end
35
+ view String, :domid do |str| ('#' + str).inspect end
36
+ view String, :prop do |str| '[' + str.inspect + ']' end
37
+ view String, :code do |str, s = "($scope)"|
38
+ str.gsub(/\{\{(.*?)\}\}/){
39
+ s + context($1, :prop)
40
+ }
41
+ end
42
+ view String, :template do |text, s = "($scope)"|
43
+ r = text.split(/(\{\{.*?\}\})/)
44
+ outtext = ""
45
+ r.each{|a|
46
+ if a =~ /\{\{(.*?)\}\}/
47
+ outtext << '" + ' << s << context($1, :prop) << '+ "'
48
+ else
49
+ outtext << a.inspect[1..-2]
50
+ end
51
+ }
52
+ outtext = '"' << outtext << '"'
53
+ end
54
+
55
+ view String, :models do |text|
56
+ r = text.split(/(\{\{.*?\}\})/)
57
+ out = []
58
+ r.each{|a|
59
+ if a =~ /\{\{(.*?)\}\}/
60
+ out << $1
61
+ end
62
+ }
63
+ out
64
+ end
65
+
66
+ view Hash, :models do |hsh|
67
+ out = []
68
+ hsh.each{|k, v|
69
+ out.concat context(k, :models)
70
+ out.concat context(v, :models)
71
+ }
72
+ out.uniq
73
+ end
74
+
75
+
76
+ model 'element' do
77
+ %{
78
+ <<%=tagname%> id=<%=context domid, :attrval%>></<%=tagname%>>
79
+ }
80
+ end
81
+
82
+ get('element').class.class_eval do
83
+ def domid
84
+ id_.tr(".", "_")
85
+ end
86
+ end
87
+
88
+
89
+ model 'value_changed' do
90
+ %{
91
+ document.querySelector(<%= context element_id, :domid %>).oninput = function(){
92
+ ($scope)<%= context modelname, :prop %> = this.value
93
+ update(<%= context modelname, :jsstr %>)
94
+ }
95
+ }
96
+ end
97
+
98
+ model 'load' do
99
+ %{
100
+ document.querySelector(<%= context element_id, :domid %>).oninput()
101
+ }
102
+ end
103
+
104
+
105
+ model 'update' do
106
+ %{
107
+ <% models.uniq.each do |m|%>
108
+ if(typeof $views<%=context(m, :prop)%> === 'undefined'){
109
+ $views<%=context(m, :prop)%> = []
110
+ }
111
+ $views<%=context(m, :prop)%>.push(document.querySelector(<%= context element_id, :domid %>))
112
+ <% end %>
113
+ document.querySelector(<%= context element_id, :domid %>).update = function(){
114
+ <% before.each{|k, v| %>
115
+ <%= context(k, :code) %> = <%= context(v, :code) %>
116
+ <% } if before%>
117
+ this.innerHTML = <%= text %>
118
+ }
119
+ }
120
+ end
121
+
122
+
123
+ def inputbox(opt = {})
124
+ a = create 'element',
125
+ tagname: "input",
126
+ modelname: opt[:model]
127
+ link 'elements', a.id_
128
+
129
+ changed = create 'value_changed',
130
+ element_id: a.domid,
131
+ modelname: a.modelname
132
+
133
+ load = create 'load',
134
+ element_id: a.domid,
135
+ modelname: a.modelname
136
+
137
+ link 'jsevent', changed.id_
138
+ link 'jsload', load.id_
139
+ end
140
+
141
+ def div(opt = {})
142
+ a = create 'element',
143
+ tagname: "div"
144
+ link 'elements', a.id_
145
+
146
+ update = create 'update',
147
+ element_id: a.domid,
148
+ text: context(opt[:text], :template),
149
+ models: context(opt[:text], :models) +
150
+ context(opt[:before] || {}, :models),
151
+ before: opt[:before]
152
+
153
+ link 'jsevent', update.id_
154
+ end
155
+
156
+
157
+ inputbox model: 'a'
158
+ div text: 'Your name has changed to {{a}}'
159
+
160
+ inputbox model: 'op1'
161
+ inputbox model: 'op2'
162
+ div before: {"{{result}}" => "+{{op1}} * +{{op2}}"},
163
+ text: "Your answer is {{result}}"
164
+
165
+ go!
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ua/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "unifiedapp"
8
+ spec.version = Ua::VERSION
9
+ spec.authors = ["Artoria"]
10
+ spec.email = ["Artoria"]
11
+ spec.summary = %q{ Unified App Generator }
12
+ spec.description = %q{ Unified App Generator }
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ua
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Artoria
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-11 00:00:00.000000000 Z
11
+ date: 2015-05-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -55,6 +55,8 @@ files:
55
55
  - lib/missing/ostruct.rb
56
56
  - lib/ua.rb
57
57
  - lib/ua/uadb.rb
58
+ - lib/ua/util.rb
59
+ - lib/ua/util.rb~
58
60
  - lib/ua/version.rb
59
61
  - test/Hello.cpp
60
62
  - test/a.db
@@ -68,7 +70,10 @@ files:
68
70
  - test/test3.rb
69
71
  - test/test4.rb
70
72
  - test/test5.rb
73
+ - test/test6.rb
74
+ - test/test7.rb
71
75
  - ua.gemspec
76
+ - ua.gemspec~
72
77
  homepage: ''
73
78
  licenses:
74
79
  - MIT
@@ -106,3 +111,5 @@ test_files:
106
111
  - test/test3.rb
107
112
  - test/test4.rb
108
113
  - test/test5.rb
114
+ - test/test6.rb
115
+ - test/test7.rb