lanes 0.8.2 → 0.8.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +2 -0
  3. data/Gemfile +2 -3
  4. data/client/lanes/boot.jsx +1 -1
  5. data/client/lanes/index.js +0 -11
  6. data/client/lanes/jest/matchers.js +14 -0
  7. data/{lib/js/jest/mocks.js → client/lanes/jest/mocks/fetch.js} +1 -1
  8. data/client/lanes/models/base.js +0 -32
  9. data/client/lanes/screens/definition.js +7 -8
  10. data/client/lanes/screens/index.js +24 -240
  11. data/client/lanes/workspace/menu.jsx +3 -34
  12. data/client/lanes/workspace/screen.jsx +3 -3
  13. data/config/routes.rb +2 -0
  14. data/config/screens.rb +2 -2
  15. data/lanes.gemspec +10 -7
  16. data/lib/lanes/access/authentication_provider.rb +4 -4
  17. data/lib/lanes/api.rb +1 -0
  18. data/lib/lanes/api/default_routes.rb +1 -1
  19. data/lib/lanes/api/handlers/screens.rb +26 -0
  20. data/lib/lanes/api/helper_methods.rb +5 -4
  21. data/lib/lanes/cli.rb +7 -0
  22. data/lib/lanes/command/app.rb +4 -6
  23. data/lib/lanes/command/client_config.rb +59 -0
  24. data/lib/lanes/command/generate_model.rb +4 -4
  25. data/lib/lanes/command/jest.rb +14 -29
  26. data/lib/lanes/command/model_attribute.rb +6 -1
  27. data/lib/lanes/command/named_command.rb +1 -0
  28. data/lib/lanes/command/puma.rb +56 -0
  29. data/lib/lanes/command/server.rb +21 -18
  30. data/lib/lanes/command/webpack.rb +54 -0
  31. data/lib/lanes/extension.rb +0 -7
  32. data/lib/lanes/guard_tasks.rb +21 -20
  33. data/lib/lanes/rake_tasks.rb +13 -0
  34. data/lib/lanes/reloadable_sinatra.rb +24 -0
  35. data/lib/lanes/screen.rb +15 -6
  36. data/lib/lanes/spec_helper.rb +70 -136
  37. data/lib/lanes/version.rb +1 -1
  38. data/package.json +1 -1
  39. data/spec/server/api/controller_base_spec.rb +61 -53
  40. data/spec/server/spec_helper.rb +37 -45
  41. data/templates/client/models/model.js +17 -0
  42. data/templates/config/database.yml +2 -1
  43. data/templates/config/jest.config.json +14 -0
  44. data/templates/config/jest/babel-transform.js +47 -0
  45. data/templates/config/routes.rb +3 -2
  46. data/templates/config/webpack.config.js +1 -1
  47. data/templates/js/jest.config.json +2 -10
  48. data/templates/spec/client/models/model.spec.js +10 -0
  49. data/templates/spec/client/setup.js +9 -0
  50. data/templates/spec/server/spec_helper.rb +3 -11
  51. metadata +40 -41
  52. data/lib/js/jest.config.json +0 -14
  53. data/lib/js/jest/fileMock.js +0 -1
  54. data/lib/js/jest/setup.js +0 -26
  55. data/lib/js/jest/stubs/screen-definitions.js +0 -0
  56. data/lib/js/jest/styleMock.js +0 -1
  57. data/lib/js/webpack.config.js +0 -93
  58. data/lib/lanes/hot_reload_plugin.rb +0 -47
  59. data/lib/lanes/webpack.rb +0 -73
  60. data/spec/server/api/coffeescript_processor_spec.rb +0 -116
  61. data/templates/client/models/Model.coffee +0 -17
  62. data/templates/spec/client/models/ModelSpec.coffee +0 -5
@@ -3,8 +3,8 @@ import classnames from 'classnames';
3
3
  import { observer } from 'mobx-react';
4
4
  import { Grid } from 'react-flexbox-grid';
5
5
  import Box from 'grommet/components/Box';
6
-
7
6
  import Screens from '../screens';
7
+ import ScreenInstances from '../screens/instance';
8
8
 
9
9
  const ScreenView = observer((props) => {
10
10
  const { screen: Screen, ...rest } = props;
@@ -26,7 +26,7 @@ export default class Screen extends React.Component {
26
26
  componentDidMount() {
27
27
  const { screenId } = this.props.params;
28
28
  if (screenId) {
29
- const definition = Screens.getDefinition(screenId);
29
+ const definition = Screens.all.get(screenId);
30
30
  if (definition) { definition.display(); }
31
31
  }
32
32
  }
@@ -40,7 +40,7 @@ export default class Screen extends React.Component {
40
40
  align="stretch"
41
41
  flex="grow"
42
42
  >
43
- {Screens.displaying.map(s =>
43
+ {ScreenInstances.displaying.map(s =>
44
44
  <ScreenView key={s.id} {...this.props.params} screen={s} />)}
45
45
  </Box>
46
46
 
@@ -8,6 +8,8 @@ Lanes::API.routes.for_extension 'lanes' do
8
8
  end
9
9
  end
10
10
 
11
+ get 'screens.json', &Lanes::API::Handlers::Screens.get
12
+
11
13
  post "user-sessions.json", &Lanes::API::Handlers::UserSession.create
12
14
  get "user-sessions/test.json", &Lanes::API::Handlers::UserSession.check
13
15
 
@@ -20,7 +20,7 @@ Lanes::Screen.for_extension 'lanes' do | screens |
20
20
  screen.description = "Add/Remove/Modify User Accounts"
21
21
  screen.icon = "group"
22
22
  screen.group_id = "system-settings"
23
- screen.model_class = "User"
23
+ screen.model_class = "SystemSettings"
24
24
  screen.view_class = "UserManagement"
25
25
  screen.asset = 'lanes/access/screens/user-management'
26
26
  end
@@ -30,7 +30,7 @@ Lanes::Screen.for_extension 'lanes' do | screens |
30
30
  screen.description = "Update System Settings"
31
31
  screen.icon = "cogs"
32
32
  screen.group_id = "system-settings"
33
- screen.model_class = "User"
33
+ screen.model_class = "SystemSettings"
34
34
  screen.asset = 'lanes/screens/system-settings'
35
35
  end
36
36
 
@@ -24,14 +24,14 @@ Gem::Specification.new do |spec|
24
24
 
25
25
  spec.required_ruby_version = ">= 2.0"
26
26
 
27
- spec.add_dependency "activejob", "~> 5.0"
28
- spec.add_dependency "activerecord", "~> 5.0"
29
- spec.add_dependency "actioncable", "~> 5.0"
27
+ spec.add_dependency "activejob", "~> 5.0.2"
28
+ spec.add_dependency "activerecord", "~> 5.0.2"
29
+ spec.add_dependency "actioncable", "~> 5.0.2"
30
30
  spec.add_dependency "mail", "~> 2.6"
31
31
 
32
- spec.add_dependency "sinatra", "~> 2.0.0.beta2"
32
+ spec.add_dependency "sinatra", "~> 2.0.0.rc1"
33
33
  spec.add_dependency "rack", "~> 2.0"
34
- spec.add_dependency "rack-protection", "~> 2.0.0.beta2"
34
+ spec.add_dependency "rack-protection", "~> 2.0.0.rc1"
35
35
 
36
36
  spec.add_dependency "rack-cors", "~> 0.4"
37
37
  spec.add_dependency "rack-test", "~> 0.6"
@@ -43,14 +43,17 @@ Gem::Specification.new do |spec|
43
43
  spec.add_dependency "execjs", "~> 2.6"
44
44
  spec.add_dependency "fastimage", "~> 2.0"
45
45
  spec.add_dependency "guard", "~> 2.13"
46
+
47
+ spec.add_dependency "rspec-rails", "~> 3.5"
48
+
46
49
  spec.add_dependency "guard-jest", "~> 0.1"
47
- spec.add_dependency "guard-minitest", "~> 2.3"
50
+ spec.add_dependency "guard-rspec", "~> 4.7"
48
51
  spec.add_dependency "hashie", "~> 3.3"
49
52
 
50
53
  spec.add_dependency "jobba", "~> 1.4"
51
54
  spec.add_dependency "jwt", "~> 1.5"
52
55
  spec.add_dependency "mini_magick", "~> 4.3.6"
53
- spec.add_dependency "minitest-around", "~> 0.2"
56
+
54
57
  spec.add_dependency "oj", "~> 2.1"
55
58
  spec.add_dependency "pg", "~> 0.8"
56
59
  spec.add_dependency "rake", "~> 12.0"
@@ -39,11 +39,11 @@ module Lanes
39
39
  return false if current_user.nil?
40
40
  case request.request_method
41
41
  when 'GET'
42
- klass.can_read_attributes?(request.params,current_user)
43
- when 'POST','PATCH','PUT'
44
- klass.can_write_attributes?(request.params,current_user)
42
+ klass.can_read_attributes?(request.params, current_user)
43
+ when 'POST', 'PATCH', 'PUT'
44
+ klass.can_write_attributes?(request.params, current_user)
45
45
  when 'DELETE'
46
- klass.can_delete_attributes?(request.params,current_user)
46
+ klass.can_delete_attributes?(request.params, current_user)
47
47
  else
48
48
  false
49
49
  end
@@ -11,6 +11,7 @@ require_relative 'api/helper_methods'
11
11
  require_relative 'api/pub_sub'
12
12
  require_relative 'api/handlers/user_session';
13
13
  require_relative 'api/handlers/asset';
14
+ require_relative 'api/handlers/screens';
14
15
  require_relative 'api/root'
15
16
 
16
17
  module Lanes
@@ -30,6 +30,6 @@ module Lanes
30
30
 
31
31
  end
32
32
 
33
- API.set_root_view :lanes_root_view
33
+ # API.set_root_view :lanes_root_view
34
34
 
35
35
  end
@@ -0,0 +1,26 @@
1
+ require_relative '../../access/user'
2
+
3
+ require 'irb'
4
+
5
+ module Lanes::API::Handlers
6
+
7
+ module Screens
8
+ def self.get
9
+ lambda do
10
+ authentication = Lanes::API::AuthenticationProvider.new(request)
11
+ if authentication.current_user.nil?
12
+ return json_reply std_api_reply :get, {}, success: true
13
+ end
14
+ screens = Lanes::Screen.select do | screen |
15
+ authentication.current_user.can_read?(screen.model)
16
+ end
17
+ # Lanes::Screen.each_group
18
+ json_reply std_api_reply :get, {
19
+ screens: screens.map{|s| s.identifier }
20
+ }, success: true
21
+ end
22
+ end
23
+
24
+ end
25
+
26
+ end
@@ -6,10 +6,11 @@ module Lanes
6
6
  end
7
7
 
8
8
  def lanes_javascript_tags
9
- assets = API.webpack.assets.map do | k |
10
- "<script src=\"http://localhost:#{API.webpack.port}/#{k}\"></script>"
11
- end
12
- assets.join("\n")
9
+ []
10
+ # assets = API.webpack.assets.map do | k |
11
+ # "<script src=\"http://localhost:#{API.webpack.port}/#{k}\"></script>"
12
+ # end
13
+ # assets.join("\n")
13
14
 
14
15
  # "<script src=\"http://localhost:#{API.webpack.port}/lanes.js\"></script>"
15
16
  # javascript_tag('lanes/vendor') + "\n" + javascript_tag('lanes')
@@ -31,6 +31,13 @@ module Lanes
31
31
  long_desc "start the Jest test server"
32
32
  register Command::Jest, 'jest', 'jest', 'Start the Jest test server for client code'
33
33
 
34
+ long_desc "start the webpack dev server"
35
+ register Command::Webpack, 'webpack', 'webpack', 'Start the Webpack Dev Server'
36
+
37
+ long_desc "start the Puma server"
38
+ register Command::Puma, 'puma', 'puma', 'Start the Puma(Sinata) Server'
39
+
40
+ long_desc "start the guard test runner"
34
41
  register Command::Guard, 'guard', 'guard', 'Start the Guard server'
35
42
 
36
43
  long_desc Command.usage_from_file("db")
@@ -36,8 +36,12 @@ module Lanes
36
36
  template "config/screens.rb"
37
37
  template "config/routes.rb"
38
38
  template "config/webpack.config.js"
39
+ template "config/jest.config.json"
40
+ template "config/jest/babel-transform.js"
39
41
  template "config/lanes.rb"
40
42
  template "gitignore",".gitignore"
43
+ template "spec/client/setup.js"
44
+ template "spec/server/spec_helper.rb"
41
45
 
42
46
  create_file "log/.gitkeep",""
43
47
  create_file "tmp/.gitkeep",""
@@ -56,12 +60,6 @@ module Lanes
56
60
  template "client/styles.scss", "#{client_dir}/styles.scss"
57
61
  end
58
62
 
59
- def create_spec_helpers
60
- template "spec/client/setup.js",
61
- "spec/client/setup.js"
62
- template "spec/server/spec_helper.rb",
63
- "spec/server/spec_helper.rb"
64
- end
65
63
 
66
64
  def knitterize
67
65
  say 'Installing node modules', :green
@@ -0,0 +1,59 @@
1
+ module Lanes
2
+ module Command
3
+
4
+ class ClientConfig < Thor::Group
5
+ include Thor::Actions
6
+
7
+ attr_reader :directory
8
+
9
+ attr_reader :controlling_extension
10
+ attr_reader :lanes_root_path
11
+ attr_reader :extension_path
12
+
13
+ attr_reader :module_paths
14
+
15
+ ROOT = Pathname.new(__FILE__).dirname.join("..", "..", "..")
16
+ def self.source_root
17
+ ROOT.join("templates", "js")
18
+ end
19
+
20
+ def apply_lanes_config
21
+ Lanes::Configuration.apply
22
+ Lanes::Extensions.load_controlling_config
23
+ end
24
+
25
+ def set_vars
26
+ @lanes_root_path = ROOT
27
+ @controlling_extension = Command.load_current_extension(raise_on_fail: true)
28
+ @extension_path = controlling_extension.root_path
29
+ end
30
+
31
+ def make_temp_dir
32
+ @directory = Pathname.new(Dir.mktmpdir)
33
+ end
34
+
35
+ def set_module_paths
36
+ @module_paths = Extensions.map { |e| e.root_path.join('client').to_s }.reverse + [
37
+ controlling_extension.root_path.join('node_modules').to_s,
38
+ directory.to_s
39
+ ]
40
+ end
41
+
42
+ def write_asset_files
43
+ say "Generating config in #{directory}", :green
44
+
45
+ template('jest.config.json',
46
+ directory.join('jest.config.json'), verbose: false)
47
+
48
+ template('root-view.html',
49
+ directory.join('root-view.tmpl.html'), verbose: false)
50
+
51
+ template('screens.js',
52
+ directory.join('lanes/screen-definitions.js'), verbose: false)
53
+
54
+ # set the mtime to the past, otherwise Webpack will build repeatedly for a second
55
+ FileUtils.touch directory.join('index.html').to_s, mtime: Time.now - 1.minute
56
+ end
57
+ end
58
+ end
59
+ end
@@ -38,10 +38,10 @@ module Lanes
38
38
 
39
39
  def create_client
40
40
  self.fields.unshift ModelAttribute.parse("id:integer")
41
- template "client/models/Model.coffee",
42
- "#{client_dir}/models/#{class_name}.coffee"
43
- template "spec/client/models/ModelSpec.coffee",
44
- "#{spec_dir}/models/#{class_name}Spec.coffee"
41
+ template "client/models/model.js",
42
+ "#{client_dir}/models/#{file_name}.js"
43
+ template "spec/client/models/model.spec.js",
44
+ "#{spec_dir}/models/#{file_name}.spec.js"
45
45
  end
46
46
 
47
47
  def add_route
@@ -1,49 +1,34 @@
1
- require 'guard/cli'
2
- require 'webpack_driver'
3
- require 'puma/cli'
4
- require 'guard/jest'
5
-
1
+ require_relative './client_config'
6
2
  require_relative '../extension'
7
3
  require_relative '../command'
8
- require 'irb'
4
+
9
5
  module Lanes
10
6
  module Command
11
7
 
12
8
  class Jest < Thor::Group
13
9
  include Thor::Actions
14
- ROOT = Pathname.new(__FILE__).dirname.join("..", "..", "..")
15
- def self.source_root
16
- ROOT.join("templates")
17
- end
18
10
 
19
- class_option :config_dir
20
- attr_accessor :lanes_root_path
21
- attr_accessor :extension_path
22
- attr_accessor :config_file
23
- attr_accessor :module_paths
11
+ attr_reader :config
24
12
 
25
- def apply_lanes_config
26
- Lanes::Configuration.apply
27
- Lanes::Extensions.load_controlling_config
28
- end
13
+ class_option :watch, :type => :boolean, default: false,
14
+ desc: "Whether to keep running and watch for file changes"
29
15
 
30
16
  def configure
31
- say 'Generating Jest Config', :green
32
- ext = Command.load_current_extension(raise_on_fail: true)
33
- self.extension_path = ext.root_path
34
- self.lanes_root_path = ROOT
35
- config_dir = Pathname.new(Dir.mktmpdir)
36
- self.config_file = config_dir.join("jest.config.json")
37
- self.module_paths = Extensions.asset_paths(ext, config_dir.to_s)
38
- template('js/jest.config.json', config_file, verbose: false, force: true)
17
+ @config = ClientConfig.new
18
+ @config.invoke_all
39
19
  self
40
20
  end
41
21
 
22
+ def config_file
23
+ config.directory.join('jest.config.json')
24
+ end
25
+
42
26
  def start
43
27
  say 'Starting Jest', :green
44
28
  say Dir.pwd, :yellow
45
- puts "$(npm bin)/jest --watch --config #{config_file};"
46
- exec("$(npm bin)/jest --watch --config #{config_file};")
29
+ cmd = "$(npm bin)/jest --config #{config_file}"
30
+ cmd << " --watch" if options[:watch]
31
+ exec(cmd)
47
32
  end
48
33
  end
49
34
  end
@@ -13,7 +13,8 @@ module Lanes
13
13
  attr_writer :index_name
14
14
 
15
15
  class << self
16
- def parse(column_definition)
16
+ def parse(column_definition)
17
+
17
18
  name, type, has_index = column_definition.split(':')
18
19
 
19
20
  # if user provided "name:index" instead of "name:string:index"
@@ -65,6 +66,10 @@ module Lanes
65
66
  @attr_options = attr_options
66
67
  end
67
68
 
69
+ def decorator
70
+ name == 'id' ? 'identifier' : 'field'
71
+ end
72
+
68
73
  def field_type
69
74
  @field_type ||= case type
70
75
  when :integer then :number_field
@@ -19,6 +19,7 @@ module Lanes
19
19
 
20
20
  def set_variables
21
21
  @class_name = name.underscore.camelize
22
+ @spec_dir = "spec/#{identifier}"
22
23
  @client_dir = "client/#{identifier}"
23
24
  end
24
25
 
@@ -0,0 +1,56 @@
1
+ require_relative '../extension'
2
+ require_relative '../command'
3
+
4
+ require 'irb'
5
+
6
+ module Lanes
7
+ module Command
8
+
9
+ class Puma < Thor::Group
10
+ include Thor::Actions
11
+
12
+ class_option :wait, :type => :boolean, default: true,
13
+ desc: "Whether to keep running and wait for exit"
14
+
15
+ def start
16
+ say "Starting Puma", :green
17
+ @proc = ::ChildProcess.build('puma')
18
+ @output, w = IO.pipe
19
+ @proc.io.stdout = @proc.io.stderr = w
20
+ @proc.start
21
+ w.close
22
+ @listener = listen_for_status_updates
23
+ sleep 1
24
+ unless @proc.alive?
25
+ raise "NOT LIVING"
26
+ puts @output.read
27
+ end
28
+ self
29
+ end
30
+
31
+ def maybe_wait
32
+ @proc.wait if options[:wait]
33
+ end
34
+
35
+ def stop
36
+ say "Stopping Puma", :green
37
+ @listener.kill
38
+ @proc.stop
39
+ @prop = nil
40
+ end
41
+
42
+ private
43
+
44
+
45
+ def listen_for_status_updates
46
+ Thread.new do
47
+ @output.each_line do | l |
48
+ Lanes.logger.info(l.chomp)
49
+ end
50
+ end
51
+ end
52
+
53
+
54
+ end
55
+ end
56
+ end
@@ -1,6 +1,5 @@
1
1
  require 'guard/cli'
2
- require_relative '../webpack'
3
-
2
+ require_relative '../guard_tasks'
4
3
  module Lanes
5
4
  module Command
6
5
 
@@ -11,27 +10,31 @@ module Lanes
11
10
  say "Launching testing server at http://localhost:8888/", :green
12
11
  require 'lanes/api'
13
12
  Lanes::Configuration.apply
14
- API.webpack = Lanes::Webpack.new
15
- threads = []
16
- Thread.abort_on_exception = true
17
- threads << Thread.new { API::Root.run! }
18
- threads << Thread.new do
19
- sleep 1 until API::Root.running?
20
- trap("INT") do
21
- Lanes.logger.warn("trapped in subthread")
22
- API.webpack.stop!
23
- exit
24
- end
25
- Lanes.logger.info "ok, ctrl-c trap registered"
26
- end
27
- API.webpack.start
13
+
14
+ config = ClientConfig.new
15
+ config.invoke_all
16
+
17
+ API.webpack = Lanes::Command::Webpack.new([], wait: false)
18
+ API.webpack.config = config
19
+
20
+ API.webpack.invoke_all# startup
21
+
22
+ ::Lanes::GuardTasks.client_config = config
23
+
24
+ # threads = []
25
+ # Thread.abort_on_exception = true
26
+ # threads << Thread.new { API::Root.run! }
27
+ # threads << Thread.new do
28
+ # sleep 1 until API::Root.running?
29
+ # Lanes.logger.info "ok, ctrl-c trap registered"
30
+ # end
28
31
  sleep(1) # give webpack a bit of time to fail if it's going to
29
- unless API.webpack.alive?
32
+ unless API.webpack.process.alive?
30
33
  puts API.webpack.messages
31
34
  exit 1
32
35
  end
33
36
  Guard.start # will block until complete
34
- API.webpack.stop # stop webpack after guard completes
37
+ API.webpack.process.stop # stop webpack after guard completes
35
38
  end
36
39
  end
37
40
  end