localtower 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5f998e6e6a73708425db8efea41a2dd1693a8b11
4
- data.tar.gz: f07cdd274b9ba4d12e1de6e9818d1c9c369cf15e
3
+ metadata.gz: ba7763048711f0533d77bbe20b4918e2ae11f2e1
4
+ data.tar.gz: 6640f9f32f1cbc27e2b05dabfd0987bc7ff27a4c
5
5
  SHA512:
6
- metadata.gz: 7cb6d243f49d3d8176d4e944f990c09638b1a24304d3c483e476c069bc2185d431bdef9dd79309ea5a99fc056e7ef3ab4fd9225bad9fecf313fb6e0d2e163759
7
- data.tar.gz: 236bdf5ba3972e6f6ecb2b7501e56dce7499d997d2573cfcc9311e3c5ef3ddf3600055a6342313ea6d103949f6bdff4b339c2c2a9984b730d7213c5636141daf
6
+ metadata.gz: 8b5d643d48891eaec18c30192ccfbe2a2f5373d89c1def8038f2b9b7791128ac788905c5cc7d25fb57387e3974f37fb00660450e1edf20559890e811a1c8df2b
7
+ data.tar.gz: 5af92258f408e3f9e8320881c3e8eb140feef90f4b6f6603104224957c125772e36f4a415ca5dccac6e5263cd086ff2054c53aeaee2b77358473017845e0c857
data/README.md CHANGED
@@ -1,4 +1,6 @@
1
- # Localtower
1
+ <p align="center">
2
+ <img src="https://raw.githubusercontent.com/damln/localtower/master/public/logo-localtower-white-300.png" alt="Localtower">
3
+ </p>
2
4
 
3
5
  ### See the schema
4
6
  ![Schema](https://raw.githubusercontent.com/damln/localtower/master/public/screenshots/v0.1.6/1_schema.png)
@@ -15,43 +17,59 @@
15
17
 
16
18
  ## INSTALL
17
19
 
18
- Add to your Gemfile:
20
+ Only tested with Rails 4.2 and Rails 5.1 (should work with any Rails 4.2+ application).
21
+ Only tested with PostgreSQL.
19
22
 
20
- # In your Gemfile
23
+ Add to your `Gemfile` file:
24
+ ```ruby
25
+ group :development do
26
+ gem "localtower"
27
+ end
28
+ ```
21
29
 
22
- group :development do
23
- gem "localtower"
24
- end
30
+ If you want the latest master branch, add to your `Gemfile` file following:
31
+ ```ruby
32
+ group :development do
33
+ gem "localtower", github: "damln/localtower"
34
+ end
35
+ ```
25
36
 
26
- In your terminal:
37
+ Run command in your terminal:
38
+ ```bash
39
+ bundle install
40
+ ```
27
41
 
28
- bundle install
42
+ Add to your `config/routes.rb`:
43
+ ```ruby
44
+ if Rails.env.development?
45
+ mount Localtower::Engine, at: "localtower"
46
+ end
47
+ ```
29
48
 
30
- Add to your routes:
49
+ ## Usage
31
50
 
32
- # in config/routes.rb
51
+ Open your browser at [http://localhost:3000/localtower](http://localhost:3000/localtower).
33
52
 
34
- if Rails.env.development?
35
- mount Localtower::Engine, at: "localtower"
36
- end
53
+ ## RSpec
37
54
 
38
- ## USAGE
55
+ Create a `spec/dummy/.env` file with the credentials to your PostgreSQL Database. It should look like this:
39
56
 
40
- Open your browser at: `http://localhost:3000/localtower`
57
+ ```
58
+ LOCALTOWER_PG_USERNAME="admin"
59
+ LOCALTOWER_PG_PASSWORD="root_or_smething"
60
+ ```
41
61
 
42
- ## TEST
43
-
44
- Create a .env file inside the spec/dummy folder with the credentials to your PostgreSQL Database. It should look like this:
45
-
46
- spec/dummy/.env:
62
+ Run the spec:
63
+ ```bash
64
+ bundle install
65
+ bundle exec rspec spec/
66
+ ```
47
67
 
48
- LOCALTOWER_PG_USERNAME="admin"
49
- LOCALTOWER_PG_PASSWORD="root_or_smething"
68
+ Notes:
69
+ Tests are currently very slow because this is testing rails commands so it boots the framework for each test. Zeus or spring should be introduced.
50
70
 
51
- Run the spec:
71
+ ## Contribute
52
72
 
53
- bundle install
54
- bundle exec rspec spec/
73
+ Thanks for reporting issues, I'll do my best.
55
74
 
56
- Notes:
57
- Tests are currently very slow because this is testing rails commands so it boots the rails for each test. Zeus or spring should be introced.
75
+ [![Analytics](https://ga-beacon.appspot.com/UA-93841935-1/github-readme?pixel)](https://github.com/damln/localtower)
@@ -48,14 +48,14 @@ module Localtower
48
48
 
49
49
  def post_models
50
50
  use_generator(::Localtower::Generators::Model, params[:models])
51
- redirect_to models_path
51
+ redirect_to relations_path
52
52
  end
53
53
 
54
54
  private
55
55
 
56
56
  def use_generator(generator_klass, options)
57
- generator = generator_klass.new(options)
58
- generator.run
57
+ generator_klass.new(options).run
59
58
  end
59
+
60
60
  end
61
61
  end
@@ -24,8 +24,7 @@
24
24
  <body>
25
25
 
26
26
  <div class="wrapper">
27
- <div class="sidebar" data-color="blue">
28
- <!-- you can change the color of the sidebar using: data-color="blue | azure | green | orange | red | purple" -->
27
+ <div class="sidebar">
29
28
 
30
29
  <div class="sidebar-wrapper">
31
30
  <ul class="nav">
@@ -68,6 +67,36 @@
68
67
  </ul>
69
68
  </div>
70
69
  </div>
70
+ <div class="tower-nav">
71
+ <div class="<%= is_active_link?(dashboard_path, :inclusive) ? "active" : nil %>">
72
+ <a class="tower-a" href="<%= dashboard_path %>">
73
+ <i class="pe-7s-home"></i>
74
+ <p>Schema</p>
75
+ </a>
76
+ </div>
77
+
78
+
79
+ <div class="<%= is_active_link?(models_path, :inclusive) ? "active" : nil %>">
80
+ <a class="tower-a" href="<%= models_path %>">
81
+ <i class="pe-7s-server"></i>
82
+ <p>New Model</p>
83
+ </a>
84
+ </div>
85
+
86
+ <div class="<%= is_active_link?(relations_path, :inclusive) ? "active" : nil %>">
87
+ <a class="tower-a" href="<%= relations_path %>">
88
+ <i class="pe-7s-shuffle"></i>
89
+ <p>New Relation</p>
90
+ </a>
91
+ </div>
92
+
93
+ <div class="<%= is_active_link?(migrations_path, :inclusive) ? "active" : nil %>">
94
+ <a class="tower-a" href="<%= migrations_path %>">
95
+ <i class="pe-7s-edit"></i>
96
+ <p>New Migration</p>
97
+ </a>
98
+ </div>
99
+ </div>
71
100
 
72
101
  <div class="main-panel">
73
102
  <div class="content">
@@ -61,7 +61,7 @@
61
61
 
62
62
  <td>
63
63
  <div class="pull-right">
64
- <button class="btn btn-danger btn-xs" data-selector="remove">Remove</button>
64
+ <button class="btn btn-danger btn-xs pointer" data-selector="remove">Remove</button>
65
65
  </div>
66
66
  </td>
67
67
  </tr>
@@ -69,8 +69,8 @@
69
69
  </table>
70
70
 
71
71
  <div class="row">
72
- <div class="col-md-12">
73
- <button class="btn btn-warning btn-xs pull-right" data-selector="duplicate">Add a field</button>
72
+ <div class="col-md-12 text-center">
73
+ <i class="pe-7s-plus pointer" data-selector="duplicate" style="font-size: 3em;"></i>
74
74
  </div>
75
75
  </div>
76
76
 
@@ -22,8 +22,9 @@
22
22
  <table class="table table-hover table-striped">
23
23
  <thead>
24
24
  <th>Field</th>
25
- <th>Kind</th>
26
- <th>index?</th>
25
+ <th>Type</th>
26
+ <th>Default</th>
27
+ <th>Index?</th>
27
28
  <th>Can be null?</th>
28
29
  <th></th>
29
30
  </thead>
@@ -36,6 +37,9 @@
36
37
  <td>
37
38
  <%= select_tag "models[attributes][][attribute_type]", options_for_select(::Localtower::Generators::Migration::TYPES), class: "form-control" %>
38
39
  </td>
40
+ <td>
41
+ <%= select_tag "models[attributes][][defaults]", options_for_select(::Localtower::Generators::Migration::DEFAULTS), include_blank: true, class: "form-control" %>
42
+ </td>
39
43
  <td>
40
44
  <input type="checkbox" value="true" name="models[attributes][][index]" class="form-control">
41
45
  </td>
@@ -44,7 +48,7 @@
44
48
  </td>
45
49
  <td>
46
50
  <div class="pull-right">
47
- <button class="btn btn-danger btn-xs" data-selector="remove">Remove</button>
51
+ <button class="btn btn-danger btn-xs pointer" data-selector="remove">Remove</button>
48
52
  </div>
49
53
  </td>
50
54
  </tr>
@@ -52,8 +56,8 @@
52
56
  </table>
53
57
 
54
58
  <div class="row">
55
- <div class="col-md-12">
56
- <button class="btn btn-warning btn-xs pull-right" data-selector="duplicate">Add a field</button>
59
+ <div class="col-md-12 text-center">
60
+ <i class="pe-7s-plus pointer" data-selector="duplicate" style="font-size: 3em;"></i>
57
61
  </div>
58
62
  </div>
59
63
 
@@ -12,7 +12,7 @@
12
12
  <%= form_tag relations_path, class: "form" do %>
13
13
  <div class="row">
14
14
  <div class="form-group">
15
- <div class="col-md-offset-4 col-md-4">
15
+ <div class="col-md-offset-4 col-sm-offset-3 col-md-4 col-sm-6">
16
16
  <div class="form-group">
17
17
  <div class="text-center">
18
18
  <label>Name of the Model (optional)</label>
@@ -23,20 +23,20 @@
23
23
 
24
24
  <div class="clearfix"></div>
25
25
 
26
- <div class="col-md-5">
26
+ <div class="col-md-5 col-sm-5">
27
27
  <label>Model 1:</label>
28
28
 
29
29
  <%= select("relations", "model_one_name", ::Localtower::Tools.models.collect {|p| [ p, p ] }, {include_blank: false}, class: "form-control") %>
30
30
  </div>
31
31
 
32
- <div class="col-md-2">
32
+ <div class="col-md-2 col-sm-2">
33
33
  <div class="text-center">
34
34
  <br>
35
35
  <i class="pe-7s-loop" style="font-size: 3em;"></i>
36
36
  </div>
37
37
  </div>
38
38
 
39
- <div class="col-md-5">
39
+ <div class="col-md-5 col-sm-5">
40
40
  <label>Model 2:</label>
41
41
  <%= select("relations", "model_two_name", ::Localtower::Tools.models.collect {|p| [ p, p ] }, {include_blank: false}, class: "form-control") %>
42
42
  </div>
@@ -140,6 +140,10 @@ module Localtower
140
140
  'drop_table',
141
141
  ].freeze
142
142
 
143
+ DEFAULTS = [
144
+ "true", "false", "nil"
145
+ ]
146
+
143
147
  # @opts =
144
148
  def initialize(opts)
145
149
  @thor = ThorGeneratorMigration.new
@@ -24,6 +24,10 @@ module Localtower
24
24
 
25
25
  ::Localtower::Tools.perform_cmd(cmd, false)
26
26
 
27
+ if defaults_present?
28
+ insert_default_values.call
29
+ end
30
+
27
31
  if @opts['run_migrate']
28
32
  ::Localtower::Tools.perform_cmd('rake db:migrate', false)
29
33
  # ::Localtower::Tools.perform_cmd('rake db:migrate RAILS_ENV=test', false)
@@ -31,6 +35,24 @@ module Localtower
31
35
 
32
36
  self
33
37
  end
38
+
39
+ private
40
+
41
+ def defaults_present?
42
+ return false unless @opts['attributes'].any? { |attr| attr["defaults"].present? }
43
+ true
44
+ end
45
+
46
+ def params_for_defaults
47
+ @opts['attributes'].each_with_object([]) do |attr, arr|
48
+ arr << Hash[ attr['attribute_name'], attr['defaults'] ] unless attr['defaults'].empty?
49
+ end
50
+ end
51
+
52
+ def insert_default_values
53
+ ::Localtower::Generators::ServiceObjects::InsertDefaults.new(params_for_defaults)
54
+ end
55
+
34
56
  end
35
57
  end
36
58
  end
@@ -0,0 +1,64 @@
1
+ module Localtower
2
+ module Generators
3
+ module ServiceObjects
4
+ class InsertDefaults
5
+
6
+ def initialize(attributes)
7
+ @attributes = attributes
8
+ end
9
+
10
+ def call
11
+ insert_defaults
12
+ end
13
+
14
+ private
15
+
16
+ attr_reader :attributes
17
+
18
+ def insert_defaults
19
+ attributes.each do |attribute|
20
+ attribute.each do |attr_key, attr_value|
21
+ process_migration_file(attr_key, attr_value)
22
+ end
23
+ end
24
+ build_file(file_lines)
25
+ end
26
+
27
+ def process_migration_file(attr_key, attr_value)
28
+ file_lines.map do |line|
29
+ attach_default_value(line, attr_key, attr_value)
30
+ end
31
+ end
32
+
33
+ def attach_default_value(line, attr_key, attr_value)
34
+ if table_attribute_line?(line) and line.include? attr_key
35
+ build_line(line, attr_value)
36
+ else
37
+ line
38
+ end
39
+ end
40
+
41
+ def build_file(lines)
42
+ File.open(latest_migration, 'w') { |f| f.puts lines }
43
+ end
44
+
45
+ def build_line(line, attr_value)
46
+ line.gsub!("\n", "") << ", default: " << "#{attr_value}" << "\n"
47
+ end
48
+
49
+ def latest_migration
50
+ @latest_migration ||= Dir["#{Rails.root}/db/migrate/*"].last
51
+ end
52
+
53
+ def file_lines
54
+ @file_lines ||= File.readlines(latest_migration)
55
+ end
56
+
57
+ def table_attribute_line?(line)
58
+ line.squish.start_with? "t."
59
+ end
60
+
61
+ end
62
+ end
63
+ end
64
+ end
@@ -19,19 +19,19 @@ module Localtower
19
19
  all_folders = (app_folders + lib_folders).flatten
20
20
 
21
21
  all_folders.each do |file|
22
- # load file
23
- ActiveSupport::Dependencies.require_or_load(file)
22
+ begin
23
+ ActiveSupport::Dependencies.require_or_load(file)
24
+ rescue Exception => e
25
+ puts "Error loading: #{file}"
26
+ end
24
27
  end
25
28
  end
26
29
 
27
30
  def models
28
31
  self.force_reload!
29
32
 
30
- klass_parent = defined?(ApplicationRecord) ? ApplicationRecord : ActiveRecord::Base
31
-
32
- Dir["#{Rails.root}/app/models/\*.rb"].map { |f|
33
- File.basename(f, '.*').camelize.constantize
34
- }.select { |klass| klass != klass_parent }.select { |klass| klass.respond_to?(:columns_hash) }
33
+ root_klass = defined?(ApplicationRecord) ? ApplicationRecord : ActiveRecord::Base
34
+ root_klass.subclasses
35
35
  end
36
36
 
37
37
  def models_presented
@@ -1,3 +1,3 @@
1
1
  module Localtower
2
- VERSION = '0.1.7'.freeze
2
+ VERSION = '0.1.8'.freeze
3
3
  end
data/public/css/app.css CHANGED
@@ -1,3 +1,46 @@
1
+
2
+ .tower-nav{
3
+ display: none;
4
+ justify-content: space-around;
5
+ padding: 10px 0 0;
6
+ background-color: #1F77D0;
7
+ text-align: center;
8
+ }
9
+
10
+ .tower-nav div{
11
+ display: inline;
12
+ border-radius: 4px;
13
+ padding: 5px;
14
+ margin-bottom: 10px;
15
+ }
16
+
17
+ .tower-nav div:hover{
18
+ background: rgba(255, 255, 255, 0.23);
19
+ }
20
+
21
+ .tower-a{
22
+ display: inline-block;
23
+ color: white;
24
+ }
25
+
26
+ .tower-a:hover{
27
+ color: white;
28
+ }
29
+
30
+ .tower-nav p{
31
+ margin: 0;
32
+ line-height: 30px;
33
+ font-size: 12px;
34
+ font-weight: 600;
35
+ text-transform: uppercase;
36
+ }
37
+
38
+ @media (max-width: 991px) {
39
+ .tower-nav{
40
+ display: flex;
41
+ }
42
+ }
43
+
1
44
  .full-message {
2
45
  z-index: 999;
3
46
  position: fixed;
@@ -41,3 +84,17 @@
41
84
  width: 45%;
42
85
  margin: 2%;
43
86
  }
87
+
88
+ .pointer:hover {
89
+ cursor: pointer;
90
+ opacity: 0.9;
91
+ }
92
+
93
+ .pointer:active {
94
+ position: relative;
95
+ top: 1px;
96
+ }
97
+
98
+ .sidebar:after, body > .navbar-collapse:after {
99
+ background: #1E8FE1;
100
+ }
@@ -1,19 +1,19 @@
1
1
  /*!
2
-
2
+
3
3
  =========================================================
4
4
  * Light Bootstrap Dashboard - v1.3.1.0
5
5
  =========================================================
6
-
6
+
7
7
  * Product Page: http://www.creative-tim.com/product/light-bootstrap-dashboard
8
8
  * Copyright 2017 Creative Tim (http://www.creative-tim.com)
9
9
  * Licensed under MIT (https://github.com/creativetimofficial/light-bootstrap-dashboard/blob/master/LICENSE.md)
10
-
10
+
11
11
  =========================================================
12
-
12
+
13
13
  * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
14
-
14
+
15
15
  */
16
-
16
+
17
17
  var searchVisible = 0;
18
18
  var transparent = true;
19
19
 
@@ -83,9 +83,6 @@ lbd = {
83
83
  $sidebar = $('.sidebar');
84
84
  sidebar_color = $sidebar.data('color');
85
85
 
86
- $logo = $sidebar.find('.logo').first();
87
- logo_content = $logo[0].outerHTML;
88
-
89
86
  ul_content = '';
90
87
 
91
88
  $navbar.attr('data-color',sidebar_color);
@@ -107,7 +104,7 @@ lbd = {
107
104
  '</ul>' +
108
105
  '</div>';
109
106
 
110
- navbar_content = logo_content + ul_content;
107
+ navbar_content = ul_content;
111
108
 
112
109
  $navbar.html(navbar_content);
113
110
 
@@ -179,4 +176,4 @@ function debounce(func, wait, immediate) {
179
176
  }, wait);
180
177
  if (immediate && !timeout) func.apply(context, args);
181
178
  };
182
- };
179
+ };
Binary file
Binary file
data/spec/dummy/Gemfile CHANGED
@@ -24,6 +24,7 @@ group :development, :test do
24
24
  gem "better_errors"
25
25
  gem "binding_of_caller"
26
26
  gem 'require_reloader'
27
+ gem 'pry'
27
28
 
28
29
  localtower_path = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
29
30
  gem "localtower", path: localtower_path
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: /Users/damln/Work/localtower/localtower
3
3
  specs:
4
- localtower (0.1.7)
4
+ localtower (0.1.8)
5
5
  active_link_to
6
6
  pg
7
7
  rails (>= 4.2.0)
@@ -35,8 +35,9 @@ GEM
35
35
  erubis (~> 2.7.0)
36
36
  rails-dom-testing (~> 2.0)
37
37
  rails-html-sanitizer (~> 1.0, >= 1.0.2)
38
- active_link_to (1.0.3)
38
+ active_link_to (1.0.4)
39
39
  actionpack
40
+ addressable
40
41
  activejob (5.0.1)
41
42
  activesupport (= 5.0.1)
42
43
  globalid (>= 0.3.6)
@@ -51,6 +52,8 @@ GEM
51
52
  i18n (~> 0.7)
52
53
  minitest (~> 5.1)
53
54
  tzinfo (~> 1.1)
55
+ addressable (2.5.0)
56
+ public_suffix (~> 2.0, >= 2.0.2)
54
57
  arel (7.1.4)
55
58
  better_errors (2.1.1)
56
59
  coderay (>= 1.0.0)
@@ -100,6 +103,11 @@ GEM
100
103
  nokogiri (1.7.0.1)
101
104
  mini_portile2 (~> 2.1.0)
102
105
  pg (0.19.0)
106
+ pry (0.10.4)
107
+ coderay (~> 1.1.0)
108
+ method_source (~> 0.8.1)
109
+ slop (~> 3.4)
110
+ public_suffix (2.0.5)
103
111
  puma (3.7.0)
104
112
  rack (2.0.1)
105
113
  rack-test (0.6.3)
@@ -140,6 +148,7 @@ GEM
140
148
  sprockets (>= 2.8, < 4.0)
141
149
  sprockets-rails (>= 2.0, < 4.0)
142
150
  tilt (>= 1.1, < 3)
151
+ slop (3.6.0)
143
152
  sprockets (3.7.1)
144
153
  concurrent-ruby (~> 1.0)
145
154
  rack (> 1, < 3)
@@ -174,6 +183,7 @@ DEPENDENCIES
174
183
  listen (~> 3.0.5)
175
184
  localtower!
176
185
  pg
186
+ pry
177
187
  puma
178
188
  rails (>= 5.0.1)
179
189
  require_reloader