lanes 0.0.5 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +0 -1
  3. data/Gemfile +0 -1
  4. data/README.md +2 -0
  5. data/client/lanes/data/Bootstrap.coffee +2 -2
  6. data/client/lanes/data/Collection.coffee +4 -0
  7. data/client/lanes/data/Config.coffee +0 -5
  8. data/client/lanes/data/Model.coffee +236 -150
  9. data/client/lanes/data/PubSub.coffee +6 -12
  10. data/client/lanes/data/Sync.coffee +1 -0
  11. data/client/lanes/extension/Extensions.coffee +4 -2
  12. data/client/lanes/lib/MakeBaseClass.coffee +1 -1
  13. data/client/lanes/minimal.js +11 -0
  14. data/client/lanes/minimal.scss.erb +12 -0
  15. data/client/lanes/screens/Base.coffee +1 -2
  16. data/client/lanes/screens/Instance.coffee +52 -0
  17. data/client/lanes/vendor/packaged.js +1 -2
  18. data/client/lanes/views/Base.coffee +12 -10
  19. data/client/lanes/workspace.scss.erb +3 -0
  20. data/client/lanes/workspace/index.js +2 -12
  21. data/docs/command.md +111 -0
  22. data/docs/model.md +188 -0
  23. data/docs/todo-example-part-1.md +71 -0
  24. data/docs/view.md +275 -0
  25. data/{spec/client/jasmine_examples/PlayerSpec.js → docs/welcome.md} +0 -0
  26. data/lanes.gemspec +3 -1
  27. data/lib/lanes/api/helper_methods.rb +8 -0
  28. data/lib/lanes/api/javascript_processor.rb +14 -10
  29. data/lib/lanes/api/pub_sub.rb +7 -7
  30. data/lib/lanes/api/request_wrapper.rb +1 -0
  31. data/lib/lanes/api/root.rb +2 -7
  32. data/lib/lanes/api/sprockets_compressor.rb +6 -2
  33. data/lib/lanes/api/sprockets_extension.rb +25 -9
  34. data/lib/lanes/api/test_specs.rb +13 -9
  35. data/lib/lanes/command.rb +16 -6
  36. data/lib/lanes/command/app.rb +11 -5
  37. data/lib/lanes/command/generate_model.rb +4 -3
  38. data/lib/lanes/command/generate_screen.rb +2 -1
  39. data/lib/lanes/command/generate_view.rb +1 -1
  40. data/lib/lanes/command/named_command.rb +5 -4
  41. data/lib/lanes/command/templates/Gemfile +1 -2
  42. data/lib/lanes/command/templates/client/data/Model.coffee +3 -3
  43. data/lib/lanes/command/templates/client/{namespace-extension.js → index.js} +0 -0
  44. data/lib/lanes/command/templates/client/screens/Screen.coffee +1 -3
  45. data/lib/lanes/command/templates/client/{styles/styles.scss → styles.scss} +0 -0
  46. data/lib/lanes/command/templates/client/views/View.coffee +1 -3
  47. data/lib/lanes/command/templates/config/lanes.rb +1 -1
  48. data/lib/lanes/command/templates/gitignore +1 -0
  49. data/lib/lanes/command/templates/lib/namespace/screen.rb +1 -1
  50. data/lib/lanes/command/templates/public/.gitkeep +0 -0
  51. data/lib/lanes/command/templates/spec/client/Screen.coffee +7 -0
  52. data/lib/lanes/command/templates/spec/client/views/ViewSpec.coffee +2 -2
  53. data/lib/lanes/concerns/all.rb +1 -1
  54. data/lib/lanes/concerns/sanitize_fields.rb +32 -0
  55. data/lib/lanes/concerns/set_attribute_data.rb +4 -4
  56. data/lib/lanes/db.rb +7 -8
  57. data/lib/lanes/extension.rb +37 -3
  58. data/lib/lanes/guard_tasks.rb +2 -2
  59. data/lib/lanes/model.rb +2 -2
  60. data/lib/lanes/screens.rb +1 -0
  61. data/lib/lanes/spec_helper.rb +17 -6
  62. data/{spec → lib/lanes}/testing_models.rb +1 -1
  63. data/lib/lanes/version.rb +1 -1
  64. data/npm-build/compile.coffee +1 -6
  65. data/public/javascripts/jasmine_examples/Player.js +22 -0
  66. data/public/javascripts/jasmine_examples/Song.js +7 -0
  67. data/spec/api/javascript_processor_spec.rb +6 -3
  68. data/spec/concerns/api_path_spec.rb +1 -1
  69. data/spec/concerns/association_extensions_spec.rb +7 -3
  70. data/spec/concerns/attr_accessor_with_default_spec.rb +1 -1
  71. data/spec/concerns/code_identifier_spec.rb +1 -1
  72. data/spec/concerns/export_associations_spec.rb +1 -1
  73. data/spec/concerns/export_methods_spec.rb +1 -14
  74. data/spec/concerns/export_scope_spec.rb +7 -9
  75. data/spec/concerns/exported_limits_spec.rb +1 -1
  76. data/spec/concerns/pub_sub_spec.rb +1 -1
  77. data/spec/concerns/set_attribute_data_spec.rb +16 -24
  78. data/spec/configuration_spec.rb +1 -1
  79. data/spec/helpers/lanes-helpers.coffee +61 -0
  80. data/spec/lanes/data/ModelSpec.coffee +152 -0
  81. data/spec/lanes/data/PubSubSpec.coffee +21 -0
  82. data/spec/{client/view → lanes/views}/BaseSpec.coffee +6 -26
  83. data/spec/numbers_spec.rb +1 -1
  84. data/spec/strings_spec.rb +1 -1
  85. data/views/index.erb +3 -10
  86. data/views/specs.erb +4 -1
  87. metadata +62 -16
  88. data/client/lanes/plugins/trigger.coffee +0 -15
  89. data/client/lanes/workspace/Instance.es6 +0 -64
  90. data/lib/lanes/concerns/sanitize_api_data.rb +0 -15
  91. data/spec/api/user_spec.rb +0 -52
  92. data/spec/fixtures/lanes/users.yml +0 -13
  93. data/spec/locked_fields_spec.rb +0 -27
  94. data/spec/role_collection_spec.rb +0 -19
  95. data/spec/user_role_spec.rb +0 -7
  96. data/spec/user_spec.rb +0 -53
@@ -0,0 +1,32 @@
1
+ require 'sanitize'
2
+
3
+ module Lanes
4
+ module Concerns
5
+
6
+ # @see ClassMethods
7
+ module SanitizeFields
8
+ extend ActiveSupport::Concern
9
+
10
+ module ClassMethods
11
+ # Remove invalid HTML from fields before save
12
+ # by using the "sanitize" gem's Sanitize.fragment method.
13
+ #
14
+ # Defaults to removing all HTML, but a valid Sanitize::Config
15
+ # hash can be specified as well.
16
+ def sanitize_fields(*fields)
17
+ options = fields.extract_options!
18
+ using = options[:using] || {}
19
+ before_save do
20
+ fields.each do |field|
21
+ value = read_attribute(field)
22
+ unless value.blank?
23
+ write_attribute(field, Sanitize.fragment(sanitized,using))
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ end
30
+ end
31
+ end
32
+ end
@@ -104,15 +104,15 @@ module Lanes::Concerns
104
104
 
105
105
  result[name] = if value.is_a?(Hash) && [:belongs_to,:has_one].include?(association.reflection.macro)
106
106
  target = association.target || association.build
107
- target.set_attribute_data(value)
107
+ target.set_attribute_data(value, user)
108
108
  elsif value.is_a?(Array) && :has_many == association.reflection.macro
109
- _set_attribute_data_from_collection(association, value)
109
+ _set_attribute_data_from_collection(association, value, user)
110
110
  end
111
111
  end
112
112
  end
113
113
  end
114
114
 
115
- def _set_attribute_data_from_collection(association, value)
115
+ def _set_attribute_data_from_collection(association, value, user)
116
116
 
117
117
  records = if association.loaded?
118
118
  association.target
@@ -129,7 +129,7 @@ module Lanes::Concerns
129
129
  else
130
130
  records.detect{ |r| r.id.to_s == value['id'].to_s }
131
131
  end
132
- record.set_attribute_data(association_data) if record
132
+ record.set_attribute_data(association_data, user) if record
133
133
  end
134
134
  end
135
135
 
data/lib/lanes/db.rb CHANGED
@@ -6,14 +6,13 @@ module Lanes
6
6
  attr_accessor(:config_file)
7
7
 
8
8
  def establish_connection( env = ENV['RAILS_ENV'] || 'development')
9
- file = config_file || 'config/database.yml'
10
- config = YAML::load( IO.read( file ) )
11
- ::ActiveRecord::Base.configurations = config
12
- self.connect( ::ActiveRecord::Base.configurations[ env ] )
13
- end
14
-
15
- def connect( configuration )
16
- ::ActiveRecord::Base.establish_connection( configuration )
9
+ if ENV['DATABASE_URL']
10
+ ::ActiveRecord::Base.establish_connection( ENV['DATABASE_URL'] )
11
+ else
12
+ config = YAML::load( IO.read( config_file || "config/database.yml" ) )
13
+ ::ActiveRecord::Base.configurations = config
14
+ ::ActiveRecord::Base.establish_connection( ::ActiveRecord::Base.configurations[ env ] )
15
+ end
17
16
  end
18
17
 
19
18
  def load_seed
@@ -14,6 +14,10 @@ module Lanes
14
14
  # Array of Pathname's to add to sprockets
15
15
  attr_accessor_with_default :root_path
16
16
 
17
+ # Does the extension use PubSub functionality
18
+ class_attribute :uses_pub_sub
19
+ class_attribute :uses_workspace
20
+
17
21
  # Load extension before/after the named extensions
18
22
  class_attribute :before
19
23
  class_attribute :after
@@ -26,8 +30,12 @@ module Lanes
26
30
  {}
27
31
  end
28
32
 
33
+ def stylesheet_include
34
+ self.identifier + '/styles'
35
+ end
36
+
29
37
  def javascript_include
30
- self.identifier + ".js"
38
+ self.identifier
31
39
  end
32
40
 
33
41
  def client_namespace
@@ -35,7 +43,13 @@ module Lanes
35
43
  end
36
44
 
37
45
  def client_paths
38
- [ self.root_path.join("client") ]
46
+ [ root_path.join('client') ]
47
+ end
48
+
49
+ def client_images
50
+ images = []
51
+ root_path.join('client','images').find{|path| images << path if path.file? }
52
+ images
39
53
  end
40
54
 
41
55
  def route(route_set)
@@ -60,6 +74,14 @@ module Lanes
60
74
  Definition.descendants
61
75
  end
62
76
 
77
+ def require_workspace?
78
+ all.detect{|ext| ext.uses_workspace }
79
+ end
80
+
81
+ def require_pub_sub?
82
+ all.detect{|ext| ext.uses_pub_sub }
83
+ end
84
+
63
85
  def sorted
64
86
  unmapped = all
65
87
  mapped = []
@@ -97,13 +119,22 @@ module Lanes
97
119
  end
98
120
 
99
121
  def client_bootstrap_data(view)
100
- data = {}
122
+ data = {
123
+ csrf_token: Rack::Csrf.csrf_token(view.env),
124
+ root_view: Lanes.config.root_view,
125
+ api_path: Lanes.config.mounted_at,
126
+ pub_sub: require_pub_sub?
127
+ }
101
128
  each do | ext |
102
129
  data[ext.identifier] = ext.client_bootstrap_data(view)
103
130
  end
104
131
  return data
105
132
  end
106
133
 
134
+ def client_images
135
+ each{|ext| }
136
+ end
137
+
107
138
  def load_current_config
108
139
  config_file = Pathname.getwd.join('config','lanes.rb')
109
140
  if config_file.exist?
@@ -114,4 +145,7 @@ module Lanes
114
145
  end
115
146
 
116
147
  end
148
+
149
+
150
+
117
151
  end
@@ -27,8 +27,8 @@ module Lanes
27
27
  })
28
28
 
29
29
  dsl.guard :jasmine, jasmine_options do
30
- dsl.watch(%r{^client/(.+?)\.(js|coffee)$}){ |m| "spec/client/#{m[1]}_spec.#{m[2]}" }
31
- dsl.watch(%r{^spec/client/.*(?:_s|S)pec\.coffee$})
30
+ dsl.watch(%r{^client/(.+?)\.(js|coffee)$}){ |m| "spec/#{m[1]}Spec.#{m[2]}" }
31
+ dsl.watch(%r{^spec/.*(?:_s|S)pec\.coffee$})
32
32
  matchers.client_matches.call if matchers.client_matches
33
33
  end
34
34
 
data/lib/lanes/model.rb CHANGED
@@ -17,10 +17,10 @@ module Lanes
17
17
  include Concerns::ExportScope
18
18
  include Concerns::ExportAssociations
19
19
  include Concerns::ExportJoinTables
20
- include Concerns::SanitizeApiData
21
20
  include Concerns::AssociationExtensions
22
21
  include Concerns::ApiPath
23
-
22
+ include Concerns::SanitizeFields
23
+
24
24
  end
25
25
 
26
26
  end
data/lib/lanes/screens.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'yaml'
2
+ require 'oj'
2
3
 
3
4
  module Lanes
4
5
 
@@ -1,5 +1,4 @@
1
1
  require 'minitest/autorun'
2
- require 'mocha/mini_test'
3
2
  require 'rack/test'
4
3
  require 'lanes'
5
4
  require 'lanes/api'
@@ -9,7 +8,7 @@ require 'active_record/fixtures'
9
8
  require 'minitest/around/unit'
10
9
  require 'minitest/spec'
11
10
  require 'minitest/autorun'
12
- require 'pry'
11
+ require 'mocha/mini_test'
13
12
 
14
13
  require_relative 'testing_models'
15
14
 
@@ -22,16 +21,28 @@ ActiveSupport::Dependencies.mechanism = :require
22
21
 
23
22
  module Lanes
24
23
 
24
+ class DummyUser
25
+ def can_read?(*args)
26
+ true
27
+ end
28
+ def can_write?(*args)
29
+ true
30
+ end
31
+ def can_delete?(*args)
32
+ true
33
+ end
34
+ end
35
+
25
36
  class TestCase < ActiveSupport::TestCase
26
37
  include Lanes
27
38
  include ActiveRecordMocks::IncludeMe
28
39
 
29
40
  include ActiveRecord::TestFixtures
30
41
  self.fixture_path = Pathname.new(__FILE__).dirname.join('fixtures')
31
- setup do
32
- Thread.current[:lanes_current_user] = lanes_users(:admin)
33
- Lanes::Access.calculate_model_access!
34
- end
42
+ # setup do
43
+ # #Thread.current[:lanes_current_user] = lanes_users(:admin)
44
+ # #Lanes::Access.calculate_model_access!
45
+ # end
35
46
 
36
47
  self.use_transactional_fixtures = true
37
48
  fixtures :all
@@ -42,7 +42,7 @@ module TestingModels
42
42
  end
43
43
  Tmhm.blacklist_attributes :secret_field
44
44
 
45
- Lanes::Access.calculate_model_access!
45
+ # Lanes::Access.calculate_model_access!
46
46
  yield
47
47
 
48
48
  TestModel.blacklisted_attributes.clear if TestModel.blacklisted_attributes
data/lib/lanes/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Lanes
2
2
 
3
- VERSION = "0.0.5"
3
+ VERSION = "0.0.8"
4
4
 
5
5
  end
@@ -3,13 +3,8 @@
3
3
  browserify = require 'browserify'
4
4
  fs = require 'fs'
5
5
  path = require 'path'
6
- #exposify = require 'exposify'
7
6
 
8
- # configure what we want to expose
9
- #exposify.config = { jquery: 'jQuery', underscore: '_' }
10
-
11
- browserify({ debug: true })
12
- # .transform(exposify)
7
+ browserify({ debug: false })
13
8
  .require(require.resolve('./template.js'), { entry: true })
14
9
  .bundle()
15
10
  .pipe(fs.createWriteStream(path.join(__dirname, '../client/lanes/vendor/packaged.js'), 'utf8'))
@@ -0,0 +1,22 @@
1
+ function Player() {
2
+ }
3
+ Player.prototype.play = function(song) {
4
+ this.currentlyPlayingSong = song;
5
+ this.isPlaying = true;
6
+ };
7
+
8
+ Player.prototype.pause = function() {
9
+ this.isPlaying = false;
10
+ };
11
+
12
+ Player.prototype.resume = function() {
13
+ if (this.isPlaying) {
14
+ throw new Error("song is already playing");
15
+ }
16
+
17
+ this.isPlaying = true;
18
+ };
19
+
20
+ Player.prototype.makeFavorite = function() {
21
+ this.currentlyPlayingSong.persistFavoriteStatus(true);
22
+ };
@@ -0,0 +1,7 @@
1
+ function Song() {
2
+ }
3
+
4
+ Song.prototype.persistFavoriteStatus = function(value) {
5
+ // something complicated
6
+ throw new Error("not yet implemented");
7
+ };
@@ -48,7 +48,7 @@ Bar.extend(Foo)
48
48
  EOS
49
49
 
50
50
  JS=<<-EOS
51
- (function(Lanes, _, window, undefined) {
51
+ (function(Lanes, Foo, _, window, FILE, undefined){
52
52
  var Foo;
53
53
 
54
54
  NS.Baz = (function() {
@@ -95,13 +95,16 @@ Foo = (function() {
95
95
 
96
96
  Bar.extend(Foo);
97
97
 
98
- })(window.Lanes, window._, window);
98
+ })(window.Lanes,(window.Lanes ? window.Lanes['Foo'] : null),window._, window,{namespace:(window.Lanes ? window.Lanes['Foo'] : null),extension:'Foo',file:'baz'});
99
99
  EOS
100
100
 
101
+ Scope = Struct.new(:logical_path)
101
102
 
102
103
  def test_coffeescript_generation
103
104
  template = API::CoffeeScriptWrapper.new{ |t| SCRIPT }
104
105
  assert_equal CLEANED, template.cleaned
105
- assert_equal JS.chomp, template.render
106
+
107
+
108
+ assert_equal JS.chomp, template.render(Scope.new("foo/bar/baz"))
106
109
  end
107
110
  end
@@ -1,4 +1,4 @@
1
- require_relative '../spec_helper'
1
+ require "lanes/spec_helper"
2
2
 
3
3
  class ApiPathTest < Lanes::TestCase
4
4
 
@@ -1,4 +1,4 @@
1
- require_relative '../spec_helper'
1
+ require "lanes/spec_helper"
2
2
 
3
3
 
4
4
  class AssociationExtensionsTest < Lanes::TestCase
@@ -13,8 +13,12 @@ class AssociationExtensionsTest < Lanes::TestCase
13
13
  end
14
14
 
15
15
  def test_adds_listener
16
- Tmhm.expects(:_add_event_listener).with(:save,is_a(Proc))
17
- TestModel.has_one(:tmhm,:listen=>{:save=>:on_save}, :inverse_of=>:tm)
16
+ Tmhm.belongs_to(:tm)
17
+ TestModel.has_one(:tmhm,:listen=>{:save=>:on_tmhm_save}, :inverse_of=>:tm)
18
+ tm = TestModel.new
19
+ tm.expects(:on_tmhm_save)
20
+ tm.build_tmhm
21
+ assert tm.save
18
22
  end
19
23
 
20
24
  def test_exports_associations
@@ -1,4 +1,4 @@
1
- require_relative '../spec_helper'
1
+ require "lanes/spec_helper"
2
2
 
3
3
  class AttrAccessorWithDefaultTest < Lanes::TestCase
4
4
 
@@ -1,4 +1,4 @@
1
- require_relative '../spec_helper'
1
+ require "lanes/spec_helper"
2
2
 
3
3
 
4
4
  class CodeIdentifierTest < Lanes::TestCase
@@ -1,4 +1,4 @@
1
- require_relative '../spec_helper'
1
+ require "lanes/spec_helper"
2
2
 
3
3
 
4
4
  class ExportAssociationsTest < Lanes::TestCase
@@ -1,25 +1,12 @@
1
- require_relative '../spec_helper'
1
+ require "lanes/spec_helper"
2
2
 
3
3
  class ExportMethodsTest < Lanes::TestCase
4
4
  include TestingModels
5
5
 
6
- def around(&block)
7
- with_testing_models(&block)
8
- end
9
-
10
- def setup
11
- # @model = TestModel.new
12
- # @model.bt = TestModelBelongsTo.new
13
- end
14
-
15
- def teardown
16
- # TestModel.send( :remove_method, :bt_description ) if User.new.respond_to?( :bt_description )
17
- end
18
6
 
19
7
 
20
8
  def test_simple_delegation
21
9
 
22
-
23
10
  refute TestModel.new.respond_to? :bt_description
24
11
 
25
12
  TestModel.send :delegate_and_export, "bt_description"
@@ -1,15 +1,13 @@
1
- require_relative '../spec_helper'
1
+ require "lanes/spec_helper"
2
2
 
3
3
  class ExportScopeTest < Lanes::TestCase
4
-
5
- def teardown
6
- User.send( :remove_method, :big_query ) if User.respond_to?( :account_name )
7
- end
8
-
4
+ include TestingModels
5
+
9
6
  def test_scope_method_creation
10
- refute User.respond_to?(:big_query)
11
- User.send( :export_scope, :big_query, ->{} )
12
- assert User.respond_to?(:big_query)
7
+ refute TestModel.respond_to?(:big_query)
8
+ TestModel.send( :export_scope, :big_query, ->{} )
9
+ assert TestModel.respond_to?(:big_query)
10
+ assert TestModel.has_exported_scope?(:big_query,DummyUser.new)
13
11
  end
14
12
 
15
13
  end