avo 3.0.1.beta8 → 3.0.1.beta11

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of avo might be problematic. Click here for more details.

Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/Rakefile +2 -0
  4. data/app/assets/builds/avo.base.css +17 -10
  5. data/app/components/avo/field_wrapper_component.html.erb +1 -1
  6. data/app/components/avo/fields/boolean_field/index_component.html.erb +1 -1
  7. data/app/components/avo/fields/common/badge_viewer_component.html.erb +1 -25
  8. data/app/components/avo/fields/common/badge_viewer_component.rb +24 -0
  9. data/app/components/avo/fields/common/boolean_check_component.html.erb +1 -12
  10. data/app/components/avo/fields/common/boolean_check_component.rb +2 -1
  11. data/app/components/avo/fields/common/gravatar_viewer_component.html.erb +1 -1
  12. data/app/components/avo/fields/common/gravatar_viewer_component.rb +2 -2
  13. data/app/components/avo/fields/common/heading_component.html.erb +3 -8
  14. data/app/components/avo/fields/common/heading_component.rb +1 -3
  15. data/app/components/avo/fields/external_image_field/index_component.html.erb +1 -1
  16. data/app/components/avo/fields/file_field/index_component.html.erb +2 -2
  17. data/app/components/avo/fields/gravatar_field/index_component.html.erb +1 -1
  18. data/app/components/avo/fields/heading_field/edit_component.html.erb +1 -1
  19. data/app/components/avo/fields/heading_field/show_component.html.erb +1 -1
  20. data/app/components/avo/fields/id_field/index_component.html.erb +1 -1
  21. data/app/components/avo/fields/text_field/index_component.html.erb +1 -1
  22. data/app/components/avo/index/resource_table_component.rb +2 -8
  23. data/app/components/avo/views/resource_edit_component.html.erb +9 -20
  24. data/app/controllers/avo/actions_controller.rb +8 -19
  25. data/app/controllers/avo/application_controller.rb +12 -0
  26. data/app/controllers/avo/search_controller.rb +2 -2
  27. data/app/views/layouts/avo/application.html.erb +1 -2
  28. data/avo.gemspec +1 -1
  29. data/bin/dev +2 -0
  30. data/lib/avo/base_action.rb +18 -23
  31. data/lib/avo/base_resource.rb +1 -1
  32. data/lib/avo/concerns/filters_session_handler.rb +3 -3
  33. data/lib/avo/concerns/has_items.rb +0 -4
  34. data/lib/avo/fields/badge_field.rb +1 -1
  35. data/lib/avo/fields/base_field.rb +12 -8
  36. data/lib/avo/fields/external_image_field.rb +2 -2
  37. data/lib/avo/fields/file_field.rb +2 -2
  38. data/lib/avo/fields/gravatar_field.rb +2 -2
  39. data/lib/avo/fields/heading_field.rb +5 -13
  40. data/lib/avo/fields/id_field.rb +2 -2
  41. data/lib/avo/fields/text_field.rb +2 -2
  42. data/lib/avo/resources/items/holder.rb +0 -6
  43. data/lib/avo/version.rb +1 -1
  44. data/lib/generators/avo/js/install_generator.rb +2 -2
  45. data/lib/generators/avo/tailwindcss/install_generator.rb +58 -12
  46. data/lib/generators/avo/templates/tailwindcss/avo.tailwind.css +5 -3
  47. data/lib/generators/avo/templates/tailwindcss/tailwind.config.js +11 -0
  48. data/lib/tasks/avo_tasks.rake +33 -5
  49. data/public/avo-assets/avo.base.css +51 -3962
  50. data/tailwind.preset.js +144 -0
  51. metadata +4 -2
@@ -4,12 +4,12 @@ module Avo
4
4
  attr_reader :width
5
5
  attr_reader :height
6
6
  attr_reader :radius
7
- attr_reader :link_to_resource
7
+ attr_reader :link_to_record
8
8
 
9
9
  def initialize(id, **args, &block)
10
10
  super(id, **args, &block)
11
11
 
12
- @link_to_resource = args[:link_to_resource].present? ? args[:link_to_resource] : false
12
+ @link_to_record = args[:link_to_record].present? ? args[:link_to_record] : false
13
13
 
14
14
  @width = args[:width].present? ? args[:width] : 40
15
15
  @height = args[:height].present? ? args[:height] : 40
@@ -1,7 +1,7 @@
1
1
  module Avo
2
2
  module Fields
3
3
  class FileField < BaseField
4
- attr_accessor :link_to_resource
4
+ attr_accessor :link_to_record
5
5
  attr_accessor :is_avatar
6
6
  attr_accessor :is_image
7
7
  attr_accessor :is_audio
@@ -12,7 +12,7 @@ module Avo
12
12
  def initialize(id, **args, &block)
13
13
  super(id, **args, &block)
14
14
 
15
- @link_to_resource = args[:link_to_resource].present? ? args[:link_to_resource] : false
15
+ @link_to_record = args[:link_to_record].present? ? args[:link_to_record] : false
16
16
  @is_avatar = args[:is_avatar].present? ? args[:is_avatar] : false
17
17
  @is_image = args[:is_image].present? ? args[:is_image] : @is_avatar
18
18
  @is_audio = args[:is_audio].present? ? args[:is_audio] : false
@@ -4,7 +4,7 @@ require "erb"
4
4
  module Avo
5
5
  module Fields
6
6
  class GravatarField < BaseField
7
- attr_reader :link_to_resource
7
+ attr_reader :link_to_record
8
8
  attr_reader :rounded
9
9
  attr_reader :size
10
10
  attr_reader :default
@@ -16,7 +16,7 @@ module Avo
16
16
 
17
17
  hide_on [:edit, :new]
18
18
 
19
- @link_to_resource = args[:link_to_resource].present? ? args[:link_to_resource] : false
19
+ @link_to_record = args[:link_to_record].present? ? args[:link_to_record] : false
20
20
  @rounded = args[:rounded].nil? ? true : args[:rounded]
21
21
  @size = args[:size].present? ? args[:size].to_i : 32
22
22
  @default = args[:default].present? ? ERB::Util.url_encode(args[:default]).to_s : ""
@@ -4,35 +4,27 @@ module Avo
4
4
  module Fields
5
5
  class HeadingField < BaseField
6
6
  attr_reader :as_html
7
- attr_reader :empty
8
-
9
- def initialize(content, **args, &block)
10
- # Mark the field as empty if there's no content passed
11
- @empty = content.blank?
12
- # Add dummy content
13
- content ||= SecureRandom.hex
14
7
 
8
+ def initialize(id, **args, &block)
15
9
  args[:updatable] = false
10
+ @label = args[:label] || id.to_s.humanize
16
11
 
17
- super(content, **args, &block)
12
+ super(id, **args, &block)
18
13
 
19
14
  # this field is not used to update anything
20
15
  @for_presentation_only = true
21
16
 
22
17
  hide_on :index
23
18
 
24
- @as_html = args[:as_html].present? ? args[:as_html] : false
19
+ @as_html = args[:as_html].presence || false
25
20
  end
26
21
 
27
22
  def id
28
23
  "heading_#{name.to_s.parameterize.underscore}"
29
24
  end
30
25
 
31
- # Override the value method if the field is empty
32
26
  def value
33
- return nil if empty
34
-
35
- super
27
+ block.present? ? execute_block : @label
36
28
  end
37
29
  end
38
30
  end
@@ -1,7 +1,7 @@
1
1
  module Avo
2
2
  module Fields
3
3
  class IdField < BaseField
4
- attr_reader :link_to_resource
4
+ attr_reader :link_to_record
5
5
 
6
6
  def initialize(id, **args, &block)
7
7
  args[:readonly] = true
@@ -12,7 +12,7 @@ module Avo
12
12
 
13
13
  add_boolean_prop args, :sortable, true
14
14
 
15
- @link_to_resource = args[:link_to_resource].present? ? args[:link_to_resource] : false
15
+ @link_to_record = args[:link_to_record].present? ? args[:link_to_record] : false
16
16
  end
17
17
  end
18
18
  end
@@ -1,14 +1,14 @@
1
1
  module Avo
2
2
  module Fields
3
3
  class TextField < BaseField
4
- attr_reader :link_to_resource
4
+ attr_reader :link_to_record
5
5
  attr_reader :as_html
6
6
  attr_reader :protocol
7
7
 
8
8
  def initialize(id, **args, &block)
9
9
  super(id, **args, &block)
10
10
 
11
- add_boolean_prop args, :link_to_resource
11
+ add_boolean_prop args, :link_to_record
12
12
  add_boolean_prop args, :as_html
13
13
  add_string_prop args, :protocol
14
14
  end
@@ -56,12 +56,6 @@ class Avo::Resources::Items::Holder
56
56
  add_item panel
57
57
  end
58
58
 
59
- def heading(body = nil, **args, &block)
60
- field = Avo::Fields::HeadingField.new(body, **args)
61
-
62
- add_item field
63
- end
64
-
65
59
  def sidebar(**args, &block)
66
60
  add_item Avo::Resources::Items::Sidebar::Builder.parse_block(**args, &block)
67
61
  end
data/lib/avo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Avo
2
- VERSION = "3.0.1.beta8" unless const_defined?(:VERSION)
2
+ VERSION = "3.0.1.beta11" unless const_defined?(:VERSION)
3
3
  end
@@ -31,7 +31,7 @@ module Generators
31
31
  end
32
32
 
33
33
  say "Ejecting the _head.html.erb partial"
34
- Rails::Generators.invoke("avo:eject", [":head", "--skip-avo-version"], {destination_root: Rails.root})
34
+ Rails::Generators.invoke("avo:eject", ["--partial", ":head", "--skip-avo-version"], {destination_root: Rails.root})
35
35
 
36
36
  say "Adding the JS asset to the partial"
37
37
  append_to_file Rails.root.join("app", "views", "avo", "partials", "_head.html.erb"), "<%= javascript_importmap_tags \"avo.custom\" %>"
@@ -48,7 +48,7 @@ module Generators
48
48
  end
49
49
 
50
50
  say "Ejecting the _head.html.erb partial"
51
- Rails::Generators.invoke("avo:eject", [":head", "--skip-avo-version"], {destination_root: Rails.root})
51
+ Rails::Generators.invoke("avo:eject", ["--partial", ":head", "--skip-avo-version"], {destination_root: Rails.root})
52
52
 
53
53
  say "Adding the JS asset to the partial"
54
54
  append_to_file Rails.root.join("app", "views", "avo", "partials", "_head.html.erb"), "<%= javascript_include_tag \"avo.custom\", \"data-turbo-track\": \"reload\", defer: true %>"
@@ -11,17 +11,30 @@ module Generators
11
11
 
12
12
  def create_files
13
13
  unless tailwindcss_installed?
14
+ say "Installing Tailwindcss"
14
15
  system "./bin/bundle add tailwindcss-rails"
15
16
  system "./bin/rails tailwindcss:install"
16
17
  end
17
18
 
18
- unless Rails.root.join("app", "assets", "stylesheets", "avo.tailwind.css").exist?
19
- say "Add default app/assets/stylesheets/avo.tailwind.css"
20
- copy_file template_path("avo.tailwind.css"), "app/assets/stylesheets/avo.tailwind.css"
19
+ unless (path = Rails.root.join("config", "avo", "tailwind.config.js")).exist?
20
+ say "Generating the Avo config file."
21
+ copy_file template_path("tailwind.config.js"), path
22
+ end
23
+
24
+ unless (path = Rails.root.join("app", "assets", "stylesheets", "avo", "tailwindcss")).exist?
25
+ say "Generating the tailwindcss directory."
26
+ directory ::Avo::Engine.root.join("app", "assets", "stylesheets", "css", "tailwindcss"), path
27
+ end
28
+
29
+
30
+ unless (path = Rails.root.join("app", "assets", "stylesheets", "avo" ,"tailwind.css")).exist?
31
+ say "Add default tailwind.css"
32
+ copy_file template_path("avo.tailwind.css"), path
21
33
  end
22
34
 
23
35
  if Rails.root.join("Procfile.dev").exist?
24
- append_to_file "Procfile.dev", "avo_css: yarn avo:tailwindcss --watch\n"
36
+ say "Add #{cmd = "avo_css: yarn avo:tailwindcss --watch"} to Procfile.dev"
37
+ append_to_file "Procfile.dev", "#{cmd}\n"
25
38
  else
26
39
  say "Add default Procfile.dev"
27
40
  copy_file template_path("Procfile.dev"), "Procfile.dev"
@@ -30,17 +43,50 @@ module Generators
30
43
  run "gem install foreman"
31
44
  end
32
45
 
33
- # Ensure that the _pre_head.html.erb template is available
34
- unless Rails.root.join("app", "views", "avo", "partials", "_pre_head.html.erb").exist?
35
- say "Ejecting the _pre_head.html.erb partial"
36
- Rails::Generators.invoke("avo:eject", [":pre_head", "--skip-avo-version"], {destination_root: Rails.root})
46
+ script_name = "avo:tailwindcss"
47
+ script_command = "tailwindcss -i ./app/assets/stylesheets/avo/tailwind.css -o ./app/assets/builds/avo.tailwind.css -c ./config/avo/tailwind.config.js --minify"
48
+ pretty_script_command = "\"#{script_name}\": \"#{script_command}\""
49
+
50
+ if (path = Rails.root.join("package.json")).exist?
51
+ say "Add #{pretty_script_command} to package.json"
52
+ json_data = JSON.parse(File.read(path))
53
+ json_data["scripts"] ||= {}
54
+ json_data["scripts"][script_name] = script_command
55
+
56
+ File.open(path, 'w') do |file|
57
+ file.write(JSON.pretty_generate(json_data) + "\n")
58
+ end
59
+ else
60
+ say "package.json not found.", :yellow
61
+ say "Ensure you have the following script in your package.json file.", :yellow
62
+ say "\"scripts\": {\n" \
63
+ " #{pretty_script_command}\n" \
64
+ "}", :green
37
65
  end
38
66
 
39
- say "Adding the CSS asset to the partial"
40
- prepend_to_file Rails.root.join("app", "views", "avo", "partials", "_pre_head.html.erb"), "<%= stylesheet_link_tag \"avo.tailwind.css\", media: \"all\" %>"
67
+ rake_enhance = <<~RUBY
41
68
 
42
- say "Ensure you have the following script in your package.json file.", :yellow
43
- say %("scripts": { "avo:tailwindcss": "tailwindcss -i ./app/assets/stylesheets/avo.tailwind.css -o ./app/assets/builds/avo.tailwind.css --minify" }), :green
69
+ Rake::Task["assets:precompile"].enhance(["avo:sym_link"])
70
+ RUBY
71
+
72
+ if (path = Rails.root.join("Rakefile")).exist?
73
+ say "Add #{rake_enhance.strip} to Rakefile"
74
+ append_to_file path, rake_enhance
75
+ else
76
+ say "Rakefile not found.", :yellow
77
+ say "Ensure you have the following code in your Rakefile file.", :yellow
78
+ say rake_enhance, :green
79
+ end
80
+
81
+ say "Make sure you run \"bundle exec rake avo:sym_link\" before compiling the assets with the \"#{script_name}\" task.", :green
82
+ if (path = Rails.root.join("bin", "dev")).exist?
83
+ lines = File.read(path).lines
84
+
85
+ # Insert the task after the shebang line (the first line)
86
+ lines.insert(1, "bundle exec rake avo:sym_link")
87
+
88
+ File.write(path, lines.join)
89
+ end
44
90
  end
45
91
 
46
92
  no_tasks do
@@ -1,6 +1,8 @@
1
- @tailwind base;
2
- @tailwind components;
3
- @tailwind utilities;
1
+ @import 'tailwindcss/base';
2
+ # Have all of Avo's custom and plugins styles available.
3
+ @import '../../../../tmp/avo/base.css';
4
+ @import 'tailwindcss/components';
5
+ @import 'tailwindcss/utilities';
4
6
 
5
7
  /*
6
8
 
@@ -0,0 +1,11 @@
1
+ const avoPreset = require('../../tmp/avo/tailwind.preset.js')
2
+
3
+ module.exports = {
4
+ presets: [avoPreset],
5
+ content: [
6
+ ...avoPreset.content,
7
+ './app/views/**/*.html.erb',
8
+ './app/helpers/**/*.rb',
9
+ './app/javascript/**/*.js',
10
+ ]
11
+ }
@@ -1,8 +1,3 @@
1
- # desc 'Explaining what the task does'
2
- # task :avo do
3
- # # Task goes here
4
- # end
5
-
6
1
  desc "Runs the update command for all Avo gems."
7
2
  task "avo:update" do
8
3
  system "bundle update avo avo-pro avo-advanced avo-dashboards avo_filters avo-menu avo_upgrade"
@@ -63,3 +58,36 @@ task "avo:gem_paths" do
63
58
  # avo:/Users/adrian/work/avocado/avo-3,avo_filters:/Users/adrian/work/avocado/advanced/avo_filters
64
59
  puts result
65
60
  end
61
+
62
+ desc "Symlinks all Avo gems to tmp/avo/packages"
63
+ task "avo:sym_link" do
64
+ base_path = Rails.root.join("tmp", "avo").to_s.gsub("/spec/dummy", "")
65
+ packages_path = "#{base_path}/packages"
66
+ if Dir.exist?(packages_path)
67
+ `rm -rf #{packages_path}/*`
68
+ else
69
+ `mkdir -p #{packages_path}`
70
+ `touch #{packages_path}/.keep`
71
+ end
72
+
73
+ ["avo", "avo-advanced", "avo-pro", "avo-dynamic_filters", "avo-dashboards", "avo-menu"].each do |gem|
74
+ path = `bundle show #{gem} 2> /dev/null`.chomp
75
+
76
+ unless path.empty?
77
+ puts "[Avo->] Linking #{gem} to #{path}"
78
+ `ln -s #{path} #{packages_path}/#{gem}`
79
+ end
80
+ end
81
+
82
+ base_css_path = Avo::Engine.root.join("app", "assets", "builds", "avo.base.css")
83
+ dest_css_path = "#{base_path}/base.css"
84
+ `rm #{dest_css_path}` if File.exist?("#{dest_css_path}")
85
+ puts "[Avo->] Linking avo.base.css to #{base_css_path}"
86
+ `ln -s #{base_css_path} #{dest_css_path}`
87
+
88
+ base_preset_path = Avo::Engine.root.join("tailwind.preset.js")
89
+ dest_preset_path = "#{base_path}/tailwind.preset.js"
90
+ `rm #{dest_preset_path}` if File.exist?("#{dest_preset_path}")
91
+ puts "[Avo->] Linking tailwind.preset.js to #{base_preset_path}"
92
+ `ln -s #{base_preset_path} #{dest_preset_path}`
93
+ end