spina 2.7.0 → 2.8.0

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

Potentially problematic release.


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

Files changed (30) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +0 -2
  3. data/Rakefile +2 -1
  4. data/app/assets/builds/spina/tailwind.css +3460 -0
  5. data/app/assets/config/spina/manifest.js +3 -1
  6. data/app/assets/javascripts/spina/controllers/image_collection_controller.js +5 -3
  7. data/app/assets/stylesheets/spina/{_animate.css → animate.css} +0 -0
  8. data/app/assets/stylesheets/spina/{tailwind/custom.css → application.tailwind.css} +40 -46
  9. data/app/assets/stylesheets/spina/{_fonts.css.erb → fonts.css.erb} +0 -0
  10. data/app/components/spina/accounts/translations_component.html.erb +21 -0
  11. data/app/components/spina/accounts/translations_component.rb +26 -0
  12. data/app/components/spina/forms/trix_toolbar_component.html.erb +1 -1
  13. data/app/controllers/spina/admin/layout_controller.rb +1 -1
  14. data/app/controllers/spina/admin/navigation_items_controller.rb +1 -1
  15. data/app/views/layouts/spina/admin/application.html.erb +2 -2
  16. data/app/views/spina/admin/layout/edit.html.erb +2 -0
  17. data/app/views/spina/admin/navigation_items/_form.html.erb +5 -1
  18. data/config/locales/fr.yml +190 -152
  19. data/lib/generators/spina/install_generator.rb +4 -0
  20. data/lib/generators/spina/tailwind_config_generator.rb +10 -0
  21. data/{app/assets/config/spina/tailwind.config.js → lib/generators/spina/templates/app/assets/config/spina/tailwind.config.js.tt} +5 -7
  22. data/lib/spina/version.rb +1 -1
  23. data/lib/spina.rb +22 -11
  24. data/lib/tasks/install.rake +39 -0
  25. data/lib/tasks/tailwind.rake +22 -0
  26. metadata +26 -10
  27. data/app/assets/stylesheets/spina/_tailwind.css +0 -203643
  28. data/app/assets/stylesheets/spina/application.css +0 -6
  29. data/lib/spina/tailwind_purger.rb +0 -147
  30. data/lib/tasks/spina_tasks.rake +0 -75
@@ -1,6 +0,0 @@
1
- /*
2
- *= require spina/_animate
3
- *= require spina/_fonts
4
- *= require spina/_tailwind
5
- *= require_self
6
- */
@@ -1,147 +0,0 @@
1
- # This TailwindPurger was originally written by DHH in the tailwindcss-rails gem
2
- # and is licensed under the following MIT License. This class has been edited
3
- # slightly to make it work with Spina's use case.
4
- #
5
- # Copyright (c) 2020 David Heinemeier Hansson
6
- #
7
- # Permission is hereby granted, free of charge, to any person obtaining
8
- # a copy of this software and associated documentation files (the
9
- # "Software"), to deal in the Software without restriction, including
10
- # without limitation the rights to use, copy, modify, merge, publish,
11
- # distribute, sublicense, and/or sell copies of the Software, and to
12
- # permit persons to whom the Software is furnished to do so, subject to
13
- # the following conditions:
14
- #
15
- # The above copyright notice and this permission notice shall be
16
- # included in all copies or substantial portions of the Software.
17
- #
18
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
- # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
- # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
22
- # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23
- # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24
- # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
-
26
- class Spina::TailwindPurger
27
- CLASS_NAME_PATTERN = /[:A-Za-z0-9_-]+[\.]*[\\\/:A-Za-z0-9_-]*/
28
-
29
- CLASS_BREAK = /(?![-_a-z0-9\\])/i # `\b` for class selectors
30
-
31
- COMMENT = /#{Regexp.escape "/*"}.*?#{Regexp.escape "*/"}/m
32
- COMMENTS_AND_BLANK_LINES = /\A(?:^#{COMMENT}?[ \t]*(?:\n|\z)|[ \t]*#{COMMENT})+/
33
-
34
- AT_RULE = /@[^{]+/
35
- CLASSLESS_SELECTOR_GROUP = /[^.{]+/
36
- CLASSLESS_BEGINNING_OF_BLOCK = /\A\s*(?:#{AT_RULE}|#{CLASSLESS_SELECTOR_GROUP})\{\n?/
37
-
38
- SELECTOR_GROUP = /[^{]+/
39
- BEGINNING_OF_BLOCK = /\A#{SELECTOR_GROUP}\{\n?/
40
-
41
- PROPERTY_NAME = /[-_a-z0-9]+/i
42
- PROPERTY_VALUE = /(?:[^;]|;\S)+/
43
- PROPERTIES = /\A(?:\s*#{PROPERTY_NAME}:#{PROPERTY_VALUE};\n?)+/
44
-
45
- END_OF_BLOCK = /\A\s*\}\n?/
46
-
47
- attr_reader :keep_these_class_names
48
-
49
- class << self
50
- def purge(input, keeping_class_names_from_files:)
51
- new(extract_class_names_from(keeping_class_names_from_files)).purge(input)
52
- end
53
-
54
- def extract_class_names(string)
55
- string.scan(CLASS_NAME_PATTERN).uniq.sort!
56
- end
57
-
58
- def extract_class_names_from(files)
59
- Array(files).flat_map { |file| extract_class_names(file.read) }.uniq.sort!
60
- end
61
-
62
- def escape_class_selector(class_name)
63
- class_name.gsub(/\A\d|[^-_a-z0-9]/, '\\\\\0')
64
- end
65
- end
66
-
67
- def initialize(keep_these_class_names)
68
- @keep_these_class_names = keep_these_class_names
69
- end
70
-
71
- def purge(input)
72
- conveyor = Conveyor.new(input)
73
-
74
- until conveyor.done?
75
- conveyor.discard(COMMENTS_AND_BLANK_LINES) \
76
- or conveyor.conditionally_keep(PROPERTIES) { conveyor.staged_output.last != "" } \
77
- or conveyor.conditionally_keep(END_OF_BLOCK) { not conveyor.staged_output.pop } \
78
- or conveyor.stage_output(CLASSLESS_BEGINNING_OF_BLOCK) \
79
- or conveyor.stage_output(BEGINNING_OF_BLOCK) { |match| purge_beginning_of_block(match.to_s) } \
80
- or raise "infinite loop"
81
- end
82
-
83
- conveyor.output
84
- end
85
-
86
- private
87
- def keep_these_selectors_pattern
88
- @keep_these_selectors_pattern ||= begin
89
- escaped_classes = @keep_these_class_names.map { |name| Regexp.escape self.class.escape_class_selector(name) }
90
- /(?:\A|,)[^.,{]*(?:[.](?:#{escaped_classes.join("|")})#{CLASS_BREAK}[^.,{]*)*(?=[,{])/
91
- end
92
- end
93
-
94
- def purge_beginning_of_block(string)
95
- purged = string.scan(keep_these_selectors_pattern).join
96
- unless purged.empty?
97
- purged.sub!(/\A,\s*/, "")
98
- purged.rstrip!
99
- purged << " {\n"
100
- end
101
- purged
102
- end
103
-
104
- class Conveyor
105
- attr_reader :output, :staged_output
106
-
107
- def initialize(input, output = +"")
108
- @input = input
109
- @output = output
110
- @staged_output = []
111
- end
112
-
113
- def consume(pattern)
114
- match = pattern.match(@input)
115
- @input = match.post_match if match
116
- match
117
- end
118
- alias :discard :consume
119
-
120
- def stage_output(pattern)
121
- if match = consume(pattern)
122
- string = block_given? ? (yield match) : match.to_s
123
- @staged_output << string
124
- string
125
- end
126
- end
127
-
128
- def keep(pattern)
129
- if match = consume(pattern)
130
- string = block_given? ? (yield match) : match.to_s
131
- @output << @staged_output.shift until @staged_output.empty?
132
- @output << string
133
- string
134
- end
135
- end
136
-
137
- def conditionally_keep(pattern)
138
- keep(pattern) do |match|
139
- (yield match) ? match.to_s : (break "")
140
- end
141
- end
142
-
143
- def done?
144
- @input.empty?
145
- end
146
- end
147
- end
@@ -1,75 +0,0 @@
1
- namespace :spina do
2
-
3
- desc "Install Spina"
4
- task install: :environment do
5
- begin
6
- ActiveRecord::Base.connection
7
- rescue ActiveRecord::NoDatabaseError
8
- puts "ERROR: database does not exist, run \"rails db:create\" first"
9
- else
10
- Rails::Command.invoke :generate, ["spina:install"]
11
- end
12
- end
13
-
14
- desc "First deploy"
15
- task first_deploy: :environment do
16
- # First deploy will run the same steps as the install generator, but skips copying files
17
- Rails::Command.invoke :generate, ["spina:install", "--first-deploy"]
18
- end
19
-
20
- desc "Generate all pages based on the theme config"
21
- task bootstrap: :environment do
22
- Spina::Account.first.save
23
- end
24
-
25
- desc "Update translations after adding locales"
26
- task update_translations: :environment do
27
- Spina.locales.each do |locale|
28
- Mobility.with_locale(locale) do
29
-
30
- Spina::Page.all.order(:id).each do |page|
31
- page.title = page.title(fallback: I18n.fallbacks[locale])
32
- page.save
33
- end
34
-
35
- end
36
- end
37
- end
38
-
39
-
40
- namespace :tailwind do
41
-
42
- desc "Compile Tailwind.css for Spina"
43
- task :compile do
44
- Dir.chdir(File.join(__dir__, "../..")) do
45
- system "npx tailwindcss@latest build -i ./app/assets/stylesheets/spina/tailwind/custom.css -o ./app/assets/stylesheets/spina/_tailwind.css -c ./app/assets/config/spina/tailwind.config.js"
46
- end
47
- end
48
-
49
- desc "Purging Tailwind classes"
50
- task purge: :environment do
51
- assets_path = "app/assets/stylesheets/spina"
52
- vendor_path = "vendor/assets/stylesheets"
53
- src = Spina::Engine.root.join(assets_path, "_tailwind.css")
54
- dest = Rails.root.join(vendor_path, "spina/_tailwind.css")
55
-
56
- # Copy Spina assets to main app
57
- FileUtils.mkdir_p Rails.root.join(vendor_path)
58
- FileUtils.cp_r Spina::Engine.root.join(assets_path), Rails.root.join(vendor_path)
59
-
60
- # Purge Tailwind classes
61
- purged = Spina::TailwindPurger.purge(File.read(src), keeping_class_names_from_files: Spina.config.tailwind_purge_content)
62
-
63
- # Overwrite Tailwind stylesheet with fewer lines
64
- File.write(dest, purged)
65
- end
66
-
67
- # Every time you execute 'rake assets:precompile'
68
- # run 'spina:tailwind:purge' first
69
- if Rake::Task.task_defined?("assets:precompile")
70
- Rake::Task['assets:precompile'].enhance ['spina:tailwind:purge']
71
- end
72
- end
73
-
74
-
75
- end