postnhost 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +8 -0
  3. data/README.md +11 -9
  4. data/Rakefile +28 -0
  5. data/app/assets/builds/postnhost/application.css +1 -1
  6. data/app/assets/stylesheets/application.tailwind.css +5 -1
  7. data/app/helpers/postnhost/application_helper.rb +0 -11
  8. data/app/views/layouts/postnhost/application.html.erb +2 -2
  9. data/app/views/layouts/postnhost/articles.html.erb +3 -3
  10. data/app/views/layouts/postnhost/product.html.erb +3 -3
  11. data/app/views/layouts/postnhost/public/templates/default.html.erb +2 -2
  12. data/app/views/layouts/postnhost/public/templates/swiss-editorial.html.erb +2 -2
  13. data/app/views/layouts/postnhost/public/templates/workspace-journal.html.erb +2 -2
  14. data/app/views/postnhost/onboarding/_post_install_checklist.html.erb +8 -8
  15. data/app/views/postnhost/pages/index.html.erb +1 -1
  16. data/app/views/postnhost/templates/edit.html.erb +1 -1
  17. data/lib/generators/postnhost/install/install_generator.rb +11 -12
  18. data/lib/generators/postnhost/locale/locale_generator.rb +1 -1
  19. data/lib/generators/postnhost/static_pages/static_pages_generator.rb +1 -1
  20. data/lib/generators/postnhost/tailwindcss/install_generator.rb +28 -25
  21. data/lib/generators/postnhost/tailwindcss/templates/host.tailwind.css +0 -3
  22. data/lib/generators/postnhost/user/user_generator.rb +1 -1
  23. data/lib/generators/postnhost/views/views_generator.rb +5 -7
  24. data/lib/postnhost/css_build.rb +68 -0
  25. data/lib/postnhost/css_scope.rb +77 -0
  26. data/lib/postnhost/sample_data.rb +1 -1
  27. data/lib/postnhost/tailwind_compiler.rb +75 -0
  28. data/lib/postnhost/tailwind_input.rb +32 -0
  29. data/lib/postnhost/version.rb +1 -1
  30. data/lib/tasks/postnhost_tasks.rake +40 -65
  31. metadata +19 -2
  32. data/lib/generators/postnhost/tailwindcss/templates/tailwind.config.js +0 -8
@@ -1,94 +1,69 @@
1
- require "json"
1
+ require "fileutils"
2
+
3
+ require "postnhost/css_build"
4
+ require "postnhost/tailwind_compiler"
5
+ require "postnhost/tailwind_input"
2
6
 
3
7
  # rubocop:disable-next Metrics/BlockLength
4
8
  namespace :postnhost do
5
9
  namespace :tailwindcss do
6
10
  def postnhost_tailwind_enabled?
7
- Rails.root.join("postnhost.tailwind.config.js").exist? &&
8
- Rails.root.join("app/assets/stylesheets/postnhost/host.tailwind.css").exist?
9
- end
10
-
11
- def tailwindcss_rails_compile_command(watch: false)
12
- return unless Gem.loaded_specs.key?("tailwindcss-rails") || Gem.loaded_specs.key?("tailwindcss-ruby")
13
-
14
- begin
15
- require "tailwindcss/ruby"
16
- rescue LoadError
17
- return
18
- end
19
-
20
- executable = Tailwindcss::Ruby.executable
21
- return if executable.blank?
22
-
23
- command = [
24
- executable,
25
- "-i", Rails.root.join("app/assets/stylesheets/postnhost/host.tailwind.css").to_s,
26
- "-o", Rails.root.join("app/assets/builds/postnhost/host.css").to_s,
27
- "-c", Rails.root.join("postnhost.tailwind.config.js").to_s,
28
- "--minify"
29
- ]
30
- command << "-w" if watch
31
- command
11
+ Rails.root.join("app/assets/stylesheets/postnhost/host.tailwind.css").exist?
32
12
  end
33
13
 
34
- def package_json_scripts
35
- path = Rails.root.join("package.json")
36
- return {} unless path.exist?
37
-
38
- JSON.parse(File.read(path)).fetch("scripts", {})
39
- rescue JSON::ParserError
40
- {}
14
+ def host_tailwind_paths
15
+ {
16
+ input: Rails.root.join("tmp/postnhost/host.tailwind.css"),
17
+ unscoped: Rails.root.join("app/assets/builds/postnhost/application.unscoped.css"),
18
+ output: Rails.root.join("app/assets/builds/postnhost/application.css")
19
+ }
41
20
  end
42
21
 
43
- def npm_compile_command(watch: false)
44
- script = watch ? "postnhost:tailwindcss:watch" : "postnhost:tailwindcss"
45
- return unless package_json_scripts.key?(script)
22
+ def write_host_tailwind_input(path)
23
+ engine_source = Postnhost::Engine.root.join("app/assets/stylesheets/application.tailwind.css")
24
+ host_source = Rails.root.join("app/assets/stylesheets/postnhost/host.tailwind.css")
46
25
 
47
- ["yarn", script]
26
+ FileUtils.mkdir_p(path.dirname)
27
+ path.write(Postnhost::TailwindInput.build(engine_source:, host_source:))
48
28
  end
49
29
 
50
- def postnhost_tailwind_command(watch: false)
51
- tailwindcss_rails_compile_command(watch:) || npm_compile_command(watch:)
30
+ def build_host_tailwind(watch: false)
31
+ paths = host_tailwind_paths
32
+ write_host_tailwind_input(paths[:input])
33
+ command = Postnhost::TailwindCompiler.new(root: Rails.root).command(
34
+ input_path: paths[:input],
35
+ output_path: paths[:unscoped],
36
+ watch:
37
+ )
38
+
39
+ Postnhost::CssBuild.run(
40
+ command:,
41
+ unscoped_path: paths[:unscoped],
42
+ output_path: paths[:output],
43
+ watch:
44
+ )
45
+ ensure
46
+ FileUtils.rm_f(paths&.dig(:input))
52
47
  end
53
48
 
54
- def print_missing_tailwind_runner_message
55
- puts <<~MSG
56
- [postnhost] No Tailwind runner found for host mode.
57
- - Option 1: add the `tailwindcss-rails` gem to your host app.
58
- - Option 2: add package.json script `postnhost:tailwindcss:watch` (and `postnhost:tailwindcss` for build).
59
- MSG
60
- end
61
-
62
- desc "Build host Tailwind CSS for Postnhost overrides"
49
+ desc "Build host Tailwind CSS for PostnHost overrides"
63
50
  task build: :environment do
64
51
  unless postnhost_tailwind_enabled?
65
- puts "[postnhost] Skipping host Tailwind build (missing postnhost.tailwind.config.js or app/assets/stylesheets/postnhost/host.tailwind.css)"
66
- next
67
- end
68
-
69
- command = postnhost_tailwind_command
70
- unless command
71
- print_missing_tailwind_runner_message
52
+ puts "[postnhost] Skipping host Tailwind build (missing app/assets/stylesheets/postnhost/host.tailwind.css)"
72
53
  next
73
54
  end
74
55
 
75
- system(*command, exception: true)
56
+ build_host_tailwind
76
57
  end
77
58
 
78
- desc "Watch host Tailwind CSS for Postnhost overrides"
59
+ desc "Watch host Tailwind CSS for PostnHost overrides"
79
60
  task watch: :environment do
80
61
  unless postnhost_tailwind_enabled?
81
- puts "[postnhost] Missing host Tailwind files. Run: rails g postnhost:tailwindcss:install"
82
- next
83
- end
84
-
85
- command = postnhost_tailwind_command(watch: true)
86
- unless command
87
- print_missing_tailwind_runner_message
62
+ puts "[postnhost] Missing host Tailwind files. Run: bin/rails g postnhost:tailwindcss:install"
88
63
  next
89
64
  end
90
65
 
91
- system(*command, exception: true)
66
+ build_host_tailwind(watch: true)
92
67
  end
93
68
  end
94
69
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: postnhost
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kirill Shevchenko
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: crass
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: nokogiri
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -662,15 +676,18 @@ files:
662
676
  - lib/generators/postnhost/static_pages/static_pages_generator.rb
663
677
  - lib/generators/postnhost/tailwindcss/install_generator.rb
664
678
  - lib/generators/postnhost/tailwindcss/templates/host.tailwind.css
665
- - lib/generators/postnhost/tailwindcss/templates/tailwind.config.js
666
679
  - lib/generators/postnhost/user/user_generator.rb
667
680
  - lib/generators/postnhost/views/views_generator.rb
668
681
  - lib/postnhost.rb
669
682
  - lib/postnhost/configuration.rb
683
+ - lib/postnhost/css_build.rb
684
+ - lib/postnhost/css_scope.rb
670
685
  - lib/postnhost/engine.rb
671
686
  - lib/postnhost/sample_data.rb
672
687
  - lib/postnhost/settings/i18n_overrides.rb
673
688
  - lib/postnhost/settings/i18n_patch.rb
689
+ - lib/postnhost/tailwind_compiler.rb
690
+ - lib/postnhost/tailwind_input.rb
674
691
  - lib/postnhost/version.rb
675
692
  - lib/tasks/postnhost_snapshots.rake
676
693
  - lib/tasks/postnhost_tasks.rake
@@ -1,8 +0,0 @@
1
- module.exports = {
2
- content: [
3
- "./app/views/postnhost/**/*.erb",
4
- "./app/views/layouts/postnhost/**/*.erb",
5
- "./app/helpers/**/*.rb",
6
- "./app/javascript/**/*.js"
7
- ]
8
- }