wedge 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +4 -0
  3. data/Gemfile +2 -0
  4. data/lib/roda/plugins/wedge.rb +15 -5
  5. data/lib/wedge/component.rb +40 -9
  6. data/lib/wedge/config.rb +2 -0
  7. data/lib/wedge/dom.rb +1 -0
  8. data/lib/wedge/events.rb +1 -1
  9. data/lib/wedge/html.rb +39 -0
  10. data/lib/wedge/middleware.rb +14 -12
  11. data/lib/wedge/plugins/uploader.rb +287 -0
  12. data/lib/wedge/require.rb +23 -35
  13. data/lib/wedge/version.rb +1 -1
  14. data/lib/wedge.rb +29 -18
  15. data/playground/Gruntfile.coffee +99 -0
  16. data/playground/app/app.rb +57 -0
  17. data/playground/app/components/index.rb +12 -0
  18. data/playground/app/components/layout.rb +38 -0
  19. data/playground/app/components/uploader.rb +32 -0
  20. data/playground/app/config/boot.rb +14 -0
  21. data/playground/app/config/variables.rb +16 -0
  22. data/{test/dummy → playground/backup}/components/bar.rb +0 -0
  23. data/{test/dummy → playground/backup}/components/base.rb +0 -0
  24. data/{test/dummy → playground/backup}/components/layout.rb +0 -0
  25. data/playground/backup/components/profile.rb +0 -0
  26. data/{test/dummy → playground/backup}/components/root.rb +12 -4
  27. data/{test/dummy → playground/backup}/forms/bar.rb +0 -0
  28. data/{test/dummy → playground/backup}/forms/foo.rb +0 -0
  29. data/playground/backup/html/layout.html +9 -0
  30. data/playground/bower.json +25 -0
  31. data/playground/config.ru +5 -0
  32. data/playground/package.json +19 -0
  33. data/playground/public/css/styles.css +2649 -0
  34. data/playground/public/css/styles.css.map +7 -0
  35. data/playground/public/includes/_head.html +9 -0
  36. data/playground/public/index.html +18 -0
  37. data/playground/public/uploader.html +33 -0
  38. data/playground/public/vendor/font-awesome/fonts/FontAwesome.otf +0 -0
  39. data/playground/public/vendor/font-awesome/fonts/fontawesome-webfont.eot +0 -0
  40. data/playground/public/vendor/font-awesome/fonts/fontawesome-webfont.svg +565 -0
  41. data/playground/public/vendor/font-awesome/fonts/fontawesome-webfont.ttf +0 -0
  42. data/playground/public/vendor/font-awesome/fonts/fontawesome-webfont.woff +0 -0
  43. data/playground/public/vendor/font-awesome/fonts/fontawesome-webfont.woff2 +0 -0
  44. data/playground/public/vendor/jquery/jquery.js +9210 -0
  45. data/playground/public/vendor/normalize-css/normalize.css +424 -0
  46. data/playground/src/css/_uploader.scss +73 -0
  47. data/playground/src/css/_variables.scss +16 -0
  48. data/playground/src/css/addons/_buttons.scss +12 -0
  49. data/playground/src/css/styles.scss +14 -0
  50. data/playground/src/includes/_head.slim +12 -0
  51. data/playground/src/index.slim +6 -0
  52. data/playground/src/uploader.slim +13 -0
  53. data/wedge.gemspec +1 -1
  54. metadata +46 -23
  55. data/test/dummy/app.rb +0 -46
  56. data/test/dummy/config.ru +0 -6
data/lib/wedge/require.rb CHANGED
@@ -1,47 +1,35 @@
1
1
  unless RUBY_ENGINE == 'opal'
2
- module Kernel
3
- # make an alias of the original require
4
- alias_method :wedge_original_require, :require
2
+ # rewrite require
3
+ def require(name)
4
+ Kernel.require name
5
5
 
6
- # rewrite require
7
- def require(name)
8
- return wedge_original_require(name) unless defined?(Wedge)
6
+ return unless defined?(Wedge) && Wedge.respond_to?(:config)
9
7
 
10
- result = wedge_original_require name
8
+ if name[/\Awedge/] || name[Dir.pwd]
9
+ name = name.sub("#{Dir.pwd}/", '').gsub(/\.rb$/, '').gsub(/\//, '__')
10
+ caller_str = "#{caller[0]}".gsub(/(#{Dir.pwd}\/|.*(?=wedge))/, '').gsub(/:.+$/, '').gsub(/\.rb$/, '').gsub(/\//, '__')
11
11
 
12
- if name[/\Awedge/] || name[Dir.pwd]
13
- name = name.sub("#{Dir.pwd}/", '').gsub(/\.rb$/, '').gsub(/\//, '__')
14
- caller_str = "#{caller[0]}".gsub(/(#{Dir.pwd}\/|.*(?=wedge))/, '').gsub(/:.+$/, '').gsub(/\.rb$/, '').gsub(/\//, '__')
15
-
16
- if !caller_str['.'] && !(Wedge.config.requires[caller_str] ||= []).include?(name)
17
- Wedge.config.requires[caller_str] << name
18
- end
12
+ if !caller_str['.'] && !(Wedge.config.requires[caller_str] ||= []).include?(name)
13
+ Wedge.config.requires[caller_str] << name
19
14
  end
20
-
21
- result
22
15
  end
16
+ end
23
17
 
24
- # make an alias of the original require
25
- alias_method :wedge_original_require_relative, :require_relative
26
-
27
- # rewrite require_relative
28
- def require_relative(name)
29
- return wedge_original_require_relative(name) unless defined?(Wedge)
30
-
31
- caller_str = "#{caller[0]}".gsub(/:.+$/, '').gsub(/\.rb$/, '')
32
- caller_path_name = caller_str.gsub(%r{(#{Dir.pwd}/|.*wedge)}, '').gsub(/:.+$/, '').gsub(/^\//, '')
33
-
34
- path_name = caller_path_name.gsub(/(?<=\/)([^\/]*)$/, "#{name}")
35
- path_name = File.expand_path(path_name).sub("#{Dir.pwd}/", '') if path_name['..']
36
- path_name = path_name.gsub(/\//, '__')
37
- file = caller_str.gsub(/(?<=\/)([^\/]*)$/, "#{name}")
38
- caller_path_name = caller_path_name.gsub(/\//, '__')
18
+ # rewrite require_relative
19
+ def require_relative(name)
20
+ caller_str = "#{caller[0]}".gsub(/:.+$/, '').gsub(/\.rb$/, '')
21
+ caller_path_name = caller_str.gsub(%r{(#{Dir.pwd}/|.*wedge)}, '').gsub(/:.+$/, '').gsub(/^\//, '')
39
22
 
40
- if !caller_path_name['.'] && !(Wedge.config.requires[caller_path_name] ||= []).include?(path_name)
41
- Wedge.config.requires[caller_path_name] << path_name
42
- end
23
+ path_name = caller_path_name.gsub(/(?<=\/)([^\/]*)$/, "#{name}")
24
+ path_name = File.expand_path(path_name).sub("#{Dir.pwd}/", '') if path_name['..']
25
+ path_name = path_name.gsub(/\//, '__')
26
+ file = caller_str.gsub(/(?<=\/)([^\/]*)$/, "#{name}")
27
+ caller_path_name = caller_path_name.gsub(/\//, '__')
43
28
 
44
- wedge_original_require file
29
+ if !caller_path_name['.'] && !(Wedge.config.requires[caller_path_name] ||= []).include?(path_name)
30
+ Wedge.config.requires[caller_path_name] << path_name
45
31
  end
32
+
33
+ Kernel.require file
46
34
  end
47
35
  end
data/lib/wedge/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Wedge
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
data/lib/wedge.rb CHANGED
@@ -32,10 +32,6 @@ class Wedge
32
32
  "#{url}#{config.cache_assets ? "/#{config.assets_key}" : ''}"
33
33
  end
34
34
 
35
- def requires
36
- @requires ||= IndifferentHash.new
37
- end
38
-
39
35
  def assets_url_regex
40
36
  @assets_url_regex ||= begin
41
37
  assets_url = ::Wedge.assets_url.gsub(%r{^\/}, '')
@@ -123,6 +119,9 @@ class Wedge
123
119
  gems_dir = ::Opal.gem_dir.gsub(/(?<=gems)\/opal-.*/, '')
124
120
  Wedge::Opal.append_path file
125
121
  Wedge::Opal.append_path Dir.pwd
122
+ # fix: make this a config option i.e.
123
+ # gems: [:ability_list]
124
+ # then grab that path and add it to the opal path list
126
125
  Dir["#{gems_dir}/**/"].sort.each do |folder|
127
126
  Wedge::Opal.append_path "#{folder}/lib"
128
127
  end
@@ -132,6 +131,8 @@ class Wedge
132
131
 
133
132
  # Return the opal javascript.
134
133
  def javascript(path_name = 'wedge', options = {})
134
+ path_name = path_name.to_s
135
+
135
136
  if server?
136
137
  javascript_cache[path_name] ||= begin
137
138
  js = build(path_name, options).javascript
@@ -151,17 +152,7 @@ class Wedge
151
152
 
152
153
  js << Opal.compile("Wedge.config.component_class[:#{comp_name}].config.data = HashObject.new(Wedge.config.component_class[:#{comp_name}].config.data.to_h.merge JSON.parse(Base64.decode64('#{compiled_data}')))")
153
154
 
154
- if requires = config.requires[path_name.gsub(/\//, '__')]
155
-
156
- requires.each do |path|
157
- next unless comp_class = Wedge.config.component_class[path]
158
-
159
- comp_name = comp_class.config.name
160
- compiled_data = Base64.encode64 comp_class.config.client_data.to_json
161
-
162
- js << Opal.compile("Wedge.config.component_class[:#{comp_name}].config.data = HashObject.new(Wedge.config.component_class[:#{comp_name}].config.data.to_h.merge JSON.parse(Base64.decode64('#{compiled_data}')))")
163
- end
164
- end
155
+ load_requires path_name, js
165
156
  end
166
157
 
167
158
  js
@@ -171,7 +162,11 @@ class Wedge
171
162
  cache = options[:cache_assets]
172
163
 
173
164
  `jQuery.ajax({ url: url, dataType: "script", cache: cache }).done(function() {`
174
- comp = Wedge.store!(options[:store].indifferent)[options[:name]]
165
+ if initialize_args = options.delete(:initialize_args)
166
+ comp = Wedge.store!(options[:store].indifferent)[options[:name], *initialize_args]
167
+ else
168
+ comp = Wedge.store!(options[:store].indifferent)[options[:name]]
169
+ end
175
170
 
176
171
  if options[:method_args].any?
177
172
  comp.send(options[:method_called], options[:method_args])
@@ -185,12 +180,28 @@ class Wedge
185
180
  end
186
181
  end
187
182
 
183
+ def load_requires path_name, js
184
+ if requires = config.requires[path_name.gsub(/\//, '__')]
185
+ requires.each do |path|
186
+ next unless comp_class = Wedge.config.component_class[path]
187
+
188
+ comp_class.config.before_compile.each { |blk| comp_class.instance_eval(&blk) }
189
+
190
+ comp_name = comp_class.config.name
191
+ compiled_data = Base64.encode64 comp_class.config.client_data.to_json
192
+
193
+ load_requires path, js
194
+
195
+ js << Opal.compile("Wedge.config.component_class[:#{comp_name}].config.data = HashObject.new(Wedge.config.component_class[:#{comp_name}].config.data.to_h.merge JSON.parse(Base64.decode64('#{compiled_data}')))")
196
+ end
197
+ end
198
+ end
199
+
188
200
  def config
189
201
  @config ||= begin
190
- args = { klass: self, component_class: IndifferentHash.new }
202
+ args = { component_class: IndifferentHash.new }
191
203
 
192
204
  unless RUBY_ENGINE == 'opal'
193
- # args[:path] = caller.first.gsub(/(?<=\.rb):.*/, '')
194
205
  args[:assets_key] = begin
195
206
  if defined?(PlatformAPI) && ENV['HEROKU_TOKEN'] && ENV['HEROKU_APP']
196
207
  heroku = PlatformAPI.connect_oauth(ENV['HEROKU_TOKEN'], default_headers: {'Range' => 'version ..; order=desc'})
@@ -0,0 +1,99 @@
1
+ module.exports = (grunt) ->
2
+
3
+ # configuration
4
+ grunt.initConfig
5
+
6
+ # grunt sass
7
+ sass:
8
+ compile:
9
+ options:
10
+ style: 'expanded'
11
+ sourcemap: 'none'
12
+ files: [
13
+ expand: true
14
+ cwd: 'src'
15
+ src: ['**/*.sass', '**/*.scss']
16
+ dest: 'public'
17
+ ext: '.css'
18
+ ]
19
+
20
+ # grunt coffee
21
+ coffee:
22
+ compile:
23
+ expand: true
24
+ cwd: 'src'
25
+ src: ['**/*.coffee']
26
+ dest: 'public'
27
+ ext: '.js'
28
+ options:
29
+ bare: true
30
+ # preserve_dirs: true
31
+
32
+ # grunt slim
33
+ slim:
34
+ dist:
35
+ options:
36
+ pretty: true
37
+ files: [{
38
+ cwd: 'src'
39
+ dest: 'public'
40
+ expand: true
41
+ src: ['**/*.slim']
42
+ ext: '.html'
43
+ }]
44
+
45
+ bake:
46
+ build:
47
+ files: [{
48
+ cwd: 'public'
49
+ src: ['**/*.html']
50
+ dest: 'public'
51
+ expand: true
52
+ }]
53
+
54
+ bowercopy:
55
+ options:
56
+ srcPrefix: 'bower_components'
57
+ scripts:
58
+ options:
59
+ destPrefix: 'public/vendor'
60
+ files:
61
+ 'jquery/jquery.js': 'jquery/dist/jquery.js'
62
+ 'font-awesome/fonts': 'font-awesome/fonts'
63
+ 'normalize-css/normalize.css': 'normalize-css/normalize.css'
64
+
65
+ # grunt watch (or simply grunt)
66
+ watch:
67
+ html:
68
+ files: ['src/**/*.html']
69
+ sass:
70
+ files: ['src/**/*.sass', 'src/**/*.scss']
71
+ tasks: ['sass']
72
+ coffee:
73
+ files: ['src/**/*.coffee']
74
+ tasks: ['coffee']
75
+ slim:
76
+ files: ['src/**/*.slim']
77
+ tasks: ['slim', 'bake:build']
78
+ options:
79
+ livereload: true
80
+
81
+ # grunt connect
82
+ connect:
83
+ server:
84
+ options:
85
+ base: 'public'
86
+ open: true
87
+ port: 8082
88
+
89
+ # load plugins
90
+ grunt.loadNpmTasks 'grunt-contrib-sass'
91
+ grunt.loadNpmTasks 'grunt-contrib-coffee'
92
+ grunt.loadNpmTasks 'grunt-contrib-watch'
93
+ grunt.loadNpmTasks 'grunt-slim'
94
+ grunt.loadNpmTasks 'grunt-bake'
95
+ grunt.loadNpmTasks 'grunt-bowercopy'
96
+ grunt.loadNpmTasks 'grunt-contrib-connect'
97
+
98
+ # tasks
99
+ grunt.registerTask 'default', ['bowercopy', 'sass', 'coffee', 'slim', 'bake', 'connect', 'watch']
@@ -0,0 +1,57 @@
1
+ class Playground
2
+ use Rack::Session::Cookie, secret: APP_SECRET
3
+
4
+ plugin :environments
5
+
6
+ configure :development do
7
+ require 'better_errors'
8
+
9
+ use BetterErrors::Middleware if defined? BetterErrors
10
+ use Rack::Static, urls: ["/public"]
11
+
12
+ BetterErrors::Middleware.allow_ip! "0.0.0.0/0"
13
+ BetterErrors.application_root = Dir.pwd
14
+ end
15
+
16
+ plugin :wedge, {
17
+ scope: self,
18
+ plugins: [:form],
19
+ settings: {
20
+ uploader: {
21
+ aws_access_key_id: AWS_ACCESS_KEY_ID,
22
+ aws_secret_access_key: AWS_SECRET_ACCESS_KEY,
23
+ bucket: AWS_BUCKET
24
+ }
25
+ }
26
+ }
27
+
28
+ plugin :assets, {
29
+ path: "#{APP_ROOT}/../", css_dir: '', js_dir: '', group_subdirs: false,
30
+ css: {
31
+ default: [
32
+ 'public/vendor/normalize-css/normalize.css',
33
+ 'public/css/styles.css',
34
+ 'bower_components/fine-uploader/_build/fine-uploader.css'
35
+ ],
36
+ },
37
+ js: {
38
+ default: [
39
+ 'public/vendor/jquery/jquery.js',
40
+ 'bower_components/fine-uploader/_build/s3.jquery.fine-uploader.js'
41
+ ],
42
+ }
43
+ }
44
+
45
+ route do |r|
46
+ r.wedge_assets
47
+ r.assets
48
+
49
+ r.root do
50
+ wedge(:index).to_js :display
51
+ end
52
+
53
+ r.on 'uploader' do
54
+ wedge(:uploader).to_js :display
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,12 @@
1
+ class Playground
2
+ class IndexComponent < Wedge::Component
3
+ name :index
4
+ html 'public/index.html' do
5
+ set_dom dom.find('body').html
6
+ end
7
+
8
+ def display
9
+ wedge(:layout).display { dom }
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,38 @@
1
+ class Playground
2
+ class LayoutComponent < Wedge::Component
3
+ name :layout
4
+ html 'public/index.html' do
5
+ head = dom.find('head')
6
+ html = dom.find('html')
7
+
8
+ inline_tags = []
9
+
10
+ head.css('script, link').each do |tag|
11
+ if (%w(src href) & tag.attributes.keys).empty?
12
+ inline_tags << tag
13
+ end
14
+ tag.remove
15
+ end
16
+
17
+ head.add_child assets [:css, :default]
18
+ html.add_child assets [:js, :default]
19
+ html.add_child Wedge.script_tag
20
+
21
+ inline_tags.each do |tag|
22
+ html.add_child tag
23
+ end
24
+
25
+ # Clear out the body
26
+ dom.find('body').html ''
27
+ end
28
+
29
+ def display options = {}, &block
30
+ return unless server?
31
+
32
+ body_dom = dom.find('body')
33
+ body_dom << block.call if block_given?
34
+
35
+ dom
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,32 @@
1
+ require_relative 'layout'
2
+ require 'wedge/plugins/uploader'
3
+
4
+ class Playground
5
+ class UploaderComponent < Wedge::Component
6
+ name :uploader
7
+ html 'public/uploader.html' do
8
+ set_dom dom.find('body').html
9
+ end
10
+
11
+ def display
12
+ wedge(:layout).display { dom }
13
+ end
14
+
15
+ def add_file data = {}
16
+ if server?
17
+ puts 'uploaded to s3'
18
+ else
19
+ puts 'uploaded to s3'
20
+ end
21
+ end
22
+
23
+ on :ready do
24
+ button = dom.find("button")
25
+ button.hide
26
+ wedge_plugin(:uploader).button button, {
27
+ wedge_name: :uploader,
28
+ wedge_method: :add_file
29
+ }
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,14 @@
1
+ require File.expand_path '../variables', __FILE__
2
+
3
+ require 'roda'
4
+ require 'wedge'
5
+
6
+ require 'pry'
7
+ require 'awesome_print'
8
+
9
+ class Playground < Roda; end
10
+
11
+ require_relative '../app'
12
+
13
+ Dir["#{APP_ROOT}/forms/*.rb"].sort.each { |file| require file }
14
+ Dir["#{APP_ROOT}/components/*.rb"].sort.each { |file| require file }
@@ -0,0 +1,16 @@
1
+ Encoding.default_external = 'UTF-8'
2
+
3
+ APP_ROOT = File.expand_path '../../', __FILE__ unless defined?(APP_ROOT)
4
+ RACK_ENV = ENV.fetch('RACK_ENV') { 'development' }.freeze
5
+
6
+ # Load environment variables
7
+ %W{.env .env.#{ENV['RACK_ENV']}}.each do |file|
8
+ File.foreach file do |line|
9
+ key, value = line.split "=", 2; ENV[key] = value.gsub('\n', '').strip
10
+ end if File.file? file
11
+ end if %w{development test}.include? RACK_ENV
12
+
13
+ APP_SECRET = ENV.fetch('APP_SECRET').freeze
14
+ AWS_ACCESS_KEY_ID = ENV.fetch('AWS_ACCESS_KEY_ID').freeze
15
+ AWS_SECRET_ACCESS_KEY = ENV.fetch('AWS_SECRET_ACCESS_KEY').freeze
16
+ AWS_BUCKET = ENV.fetch('AWS_BUCKET').freeze
File without changes
File without changes
@@ -6,7 +6,9 @@ require_relative '../forms/foo'
6
6
  class DummyApp
7
7
  class RootComponent < BaseComponent
8
8
  name :root
9
- html "<div id='foo'>bar</div>"
9
+ html html! {
10
+ div 'bar', id: 'foo'
11
+ }
10
12
 
11
13
  def display
12
14
  if server?
@@ -14,9 +16,15 @@ class DummyApp
14
16
  dom.to_html
15
17
  end
16
18
  else
17
- el = Element['<div>']
18
- el.html 'foo'
19
- dom.find('#foo').before el
19
+ html! do
20
+ div class: 'control-group fake optional' do
21
+ label 'Profile Picture', class: 'fake optional control-label'
22
+ div id: 'profile_picture'
23
+ end
24
+ end
25
+ dom.find('#foo').before html! {
26
+ div 'foo'
27
+ }
20
28
  end
21
29
  end
22
30
 
File without changes
File without changes
@@ -0,0 +1,9 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <script src="//code.jquery.com/jquery-1.11.2.js"></script>
5
+ </head>
6
+ <body>
7
+ <div id='template'>Template</div>
8
+ </body>
9
+ </html>
@@ -0,0 +1,25 @@
1
+ {
2
+ "name": "wedge",
3
+ "version": "0.0.0",
4
+ "authors": [
5
+ "cj <cjlazell@gmail.com>"
6
+ ],
7
+ "license": "MIT",
8
+ "ignore": [
9
+ "**/.*",
10
+ "node_modules",
11
+ "bower_components",
12
+ "test",
13
+ "tests"
14
+ ],
15
+ "dependencies": {
16
+ "bourbon": "~4.2.3",
17
+ "neat": "~1.7.2",
18
+ "normalize-css": "~3.0.3",
19
+ "bitters": "~1.0.0",
20
+ "font-awesome": "~4.3.0",
21
+ "jquery": "~2.1.4",
22
+ "froala": "~1.2.7",
23
+ "fine-uploader": "~5.2.1"
24
+ }
25
+ }
@@ -0,0 +1,5 @@
1
+ ENV['LC_ALL'] ||= 'en_US.utf8'
2
+
3
+ require File.expand_path '../app/config/boot', __FILE__
4
+
5
+ run Playground
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "wedge",
3
+ "description": "",
4
+ "author": "CJ Lazell <cjlazell@gmail.com>",
5
+ "version": "0.0.1",
6
+ "devDependencies": {
7
+ "bower": "~1.4.1",
8
+ "coffee-script": "~1.9.2",
9
+ "grunt": "~0.4.5",
10
+ "grunt-bake": "^0.3.13",
11
+ "grunt-bowercopy": "^1.2.0",
12
+ "grunt-contrib-coffee": "~0.13.0",
13
+ "grunt-contrib-connect": "^0.10.1",
14
+ "grunt-contrib-sass": "~0.9.2",
15
+ "grunt-contrib-watch": "~0.6.1",
16
+ "grunt-slim": "^0.1.0"
17
+ },
18
+ "license": "MIT"
19
+ }