open_blog 0.1.0 → 0.2.0

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 (43) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +27 -4
  3. data/README.md +60 -32
  4. data/app/assets/builds/open_blog/blog.css +1 -1
  5. data/app/assets/builds/open_blog/themes.css +403 -0
  6. data/app/assets/fonts/open_blog/OFL-dm-sans.txt +93 -0
  7. data/app/assets/fonts/open_blog/OFL-jetbrains-mono.txt +93 -0
  8. data/app/assets/fonts/open_blog/OFL-newsreader.txt +93 -0
  9. data/app/assets/fonts/open_blog/OFL-outfit.txt +93 -0
  10. data/app/assets/fonts/open_blog/OFL-space-grotesk.txt +93 -0
  11. data/app/assets/fonts/open_blog/dm-sans-italic-latin-ext.woff2 +0 -0
  12. data/app/assets/fonts/open_blog/dm-sans-italic-latin.woff2 +0 -0
  13. data/app/assets/fonts/open_blog/dm-sans-latin-ext.woff2 +0 -0
  14. data/app/assets/fonts/open_blog/dm-sans-latin.woff2 +0 -0
  15. data/app/assets/fonts/open_blog/jetbrains-mono-latin-ext.woff2 +0 -0
  16. data/app/assets/fonts/open_blog/jetbrains-mono-latin.woff2 +0 -0
  17. data/app/assets/fonts/open_blog/newsreader-italic-latin-ext.woff2 +0 -0
  18. data/app/assets/fonts/open_blog/newsreader-italic-latin.woff2 +0 -0
  19. data/app/assets/fonts/open_blog/newsreader-latin-ext.woff2 +0 -0
  20. data/app/assets/fonts/open_blog/newsreader-latin.woff2 +0 -0
  21. data/app/assets/fonts/open_blog/outfit-latin-ext.woff2 +0 -0
  22. data/app/assets/fonts/open_blog/outfit-latin.woff2 +0 -0
  23. data/app/assets/fonts/open_blog/space-grotesk-latin-ext.woff2 +0 -0
  24. data/app/assets/fonts/open_blog/space-grotesk-latin.woff2 +0 -0
  25. data/app/controllers/open_blog/api/v1/pages_controller.rb +5 -5
  26. data/app/helpers/open_blog/faq_helper.rb +3 -1
  27. data/app/helpers/open_blog/theme_helper.rb +29 -5
  28. data/lib/generators/open_blog/generator_support.rb +5 -5
  29. data/lib/generators/open_blog/install/install_generator.rb +22 -1
  30. data/lib/generators/open_blog/install/templates/initializer.rb.tt +1 -0
  31. data/lib/generators/open_blog/install/templates/theme/blog.css +194 -93
  32. data/lib/generators/open_blog/install/templates/theme/open_blog_theme.css +17 -81
  33. data/lib/generators/open_blog/install/templates/theme/theme.css +3 -85
  34. data/lib/generators/open_blog/views/views_generator.rb +1 -1
  35. data/lib/open_blog/build_css.rb +51 -8
  36. data/lib/open_blog/configuration.rb +37 -1
  37. data/lib/open_blog/doctor/files.rb +50 -11
  38. data/lib/open_blog/themes.rb +167 -0
  39. data/lib/open_blog/version.rb +1 -1
  40. data/lib/open_blog.rb +1 -0
  41. data/lib/tasks/open_blog.rake +1 -1
  42. data/skills/open-blog-install/SKILL.md +1 -1
  43. metadata +23 -2
@@ -0,0 +1,93 @@
1
+ Copyright 2021 The Outfit Project Authors (https://github.com/Outfitio/Outfit-Fonts)
2
+
3
+ This Font Software is licensed under the SIL Open Font License, Version 1.1.
4
+ This license is copied below, and is also available with a FAQ at:
5
+ https://scripts.sil.org/OFL
6
+
7
+
8
+ -----------------------------------------------------------
9
+ SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
10
+ -----------------------------------------------------------
11
+
12
+ PREAMBLE
13
+ The goals of the Open Font License (OFL) are to stimulate worldwide
14
+ development of collaborative font projects, to support the font creation
15
+ efforts of academic and linguistic communities, and to provide a free and
16
+ open framework in which fonts may be shared and improved in partnership
17
+ with others.
18
+
19
+ The OFL allows the licensed fonts to be used, studied, modified and
20
+ redistributed freely as long as they are not sold by themselves. The
21
+ fonts, including any derivative works, can be bundled, embedded,
22
+ redistributed and/or sold with any software provided that any reserved
23
+ names are not used by derivative works. The fonts and derivatives,
24
+ however, cannot be released under any other type of license. The
25
+ requirement for fonts to remain under this license does not apply
26
+ to any document created using the fonts or their derivatives.
27
+
28
+ DEFINITIONS
29
+ "Font Software" refers to the set of files released by the Copyright
30
+ Holder(s) under this license and clearly marked as such. This may
31
+ include source files, build scripts and documentation.
32
+
33
+ "Reserved Font Name" refers to any names specified as such after the
34
+ copyright statement(s).
35
+
36
+ "Original Version" refers to the collection of Font Software components as
37
+ distributed by the Copyright Holder(s).
38
+
39
+ "Modified Version" refers to any derivative made by adding to, deleting,
40
+ or substituting -- in part or in whole -- any of the components of the
41
+ Original Version, by changing formats or by porting the Font Software to a
42
+ new environment.
43
+
44
+ "Author" refers to any designer, engineer, programmer, technical
45
+ writer or other person who contributed to the Font Software.
46
+
47
+ PERMISSION & CONDITIONS
48
+ Permission is hereby granted, free of charge, to any person obtaining
49
+ a copy of the Font Software, to use, study, copy, merge, embed, modify,
50
+ redistribute, and sell modified and unmodified copies of the Font
51
+ Software, subject to the following conditions:
52
+
53
+ 1) Neither the Font Software nor any of its individual components,
54
+ in Original or Modified Versions, may be sold by itself.
55
+
56
+ 2) Original or Modified Versions of the Font Software may be bundled,
57
+ redistributed and/or sold with any software, provided that each copy
58
+ contains the above copyright notice and this license. These can be
59
+ included either as stand-alone text files, human-readable headers or
60
+ in the appropriate machine-readable metadata fields within text or
61
+ binary files as long as those fields can be easily viewed by the user.
62
+
63
+ 3) No Modified Version of the Font Software may use the Reserved Font
64
+ Name(s) unless explicit written permission is granted by the corresponding
65
+ Copyright Holder. This restriction only applies to the primary font name as
66
+ presented to the users.
67
+
68
+ 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
69
+ Software shall not be used to promote, endorse or advertise any
70
+ Modified Version, except to acknowledge the contribution(s) of the
71
+ Copyright Holder(s) and the Author(s) or with their explicit written
72
+ permission.
73
+
74
+ 5) The Font Software, modified or unmodified, in part or in whole,
75
+ must be distributed entirely under this license, and must not be
76
+ distributed under any other license. The requirement for fonts to
77
+ remain under this license does not apply to any document created
78
+ using the Font Software.
79
+
80
+ TERMINATION
81
+ This license becomes null and void if any of the above conditions are
82
+ not met.
83
+
84
+ DISCLAIMER
85
+ THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
86
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
87
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
88
+ OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
89
+ COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
90
+ INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
91
+ DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
92
+ FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
93
+ OTHER DEALINGS IN THE FONT SOFTWARE.
@@ -0,0 +1,93 @@
1
+ Copyright 2020 The Space Grotesk Project Authors (https://github.com/floriankarsten/space-grotesk)
2
+
3
+ This Font Software is licensed under the SIL Open Font License, Version 1.1.
4
+ This license is copied below, and is also available with a FAQ at:
5
+ http://scripts.sil.org/OFL
6
+
7
+
8
+ -----------------------------------------------------------
9
+ SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
10
+ -----------------------------------------------------------
11
+
12
+ PREAMBLE
13
+ The goals of the Open Font License (OFL) are to stimulate worldwide
14
+ development of collaborative font projects, to support the font creation
15
+ efforts of academic and linguistic communities, and to provide a free and
16
+ open framework in which fonts may be shared and improved in partnership
17
+ with others.
18
+
19
+ The OFL allows the licensed fonts to be used, studied, modified and
20
+ redistributed freely as long as they are not sold by themselves. The
21
+ fonts, including any derivative works, can be bundled, embedded,
22
+ redistributed and/or sold with any software provided that any reserved
23
+ names are not used by derivative works. The fonts and derivatives,
24
+ however, cannot be released under any other type of license. The
25
+ requirement for fonts to remain under this license does not apply
26
+ to any document created using the fonts or their derivatives.
27
+
28
+ DEFINITIONS
29
+ "Font Software" refers to the set of files released by the Copyright
30
+ Holder(s) under this license and clearly marked as such. This may
31
+ include source files, build scripts and documentation.
32
+
33
+ "Reserved Font Name" refers to any names specified as such after the
34
+ copyright statement(s).
35
+
36
+ "Original Version" refers to the collection of Font Software components as
37
+ distributed by the Copyright Holder(s).
38
+
39
+ "Modified Version" refers to any derivative made by adding to, deleting,
40
+ or substituting -- in part or in whole -- any of the components of the
41
+ Original Version, by changing formats or by porting the Font Software to a
42
+ new environment.
43
+
44
+ "Author" refers to any designer, engineer, programmer, technical
45
+ writer or other person who contributed to the Font Software.
46
+
47
+ PERMISSION & CONDITIONS
48
+ Permission is hereby granted, free of charge, to any person obtaining
49
+ a copy of the Font Software, to use, study, copy, merge, embed, modify,
50
+ redistribute, and sell modified and unmodified copies of the Font
51
+ Software, subject to the following conditions:
52
+
53
+ 1) Neither the Font Software nor any of its individual components,
54
+ in Original or Modified Versions, may be sold by itself.
55
+
56
+ 2) Original or Modified Versions of the Font Software may be bundled,
57
+ redistributed and/or sold with any software, provided that each copy
58
+ contains the above copyright notice and this license. These can be
59
+ included either as stand-alone text files, human-readable headers or
60
+ in the appropriate machine-readable metadata fields within text or
61
+ binary files as long as those fields can be easily viewed by the user.
62
+
63
+ 3) No Modified Version of the Font Software may use the Reserved Font
64
+ Name(s) unless explicit written permission is granted by the corresponding
65
+ Copyright Holder. This restriction only applies to the primary font name as
66
+ presented to the users.
67
+
68
+ 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
69
+ Software shall not be used to promote, endorse or advertise any
70
+ Modified Version, except to acknowledge the contribution(s) of the
71
+ Copyright Holder(s) and the Author(s) or with their explicit written
72
+ permission.
73
+
74
+ 5) The Font Software, modified or unmodified, in part or in whole,
75
+ must be distributed entirely under this license, and must not be
76
+ distributed under any other license. The requirement for fonts to
77
+ remain under this license does not apply to any document created
78
+ using the Font Software.
79
+
80
+ TERMINATION
81
+ This license becomes null and void if any of the above conditions are
82
+ not met.
83
+
84
+ DISCLAIMER
85
+ THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
86
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
87
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
88
+ OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
89
+ COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
90
+ INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
91
+ DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
92
+ FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
93
+ OTHER DEALINGS IN THE FONT SOFTWARE.
@@ -30,12 +30,12 @@ module OpenBlog
30
30
  [ current, created ]
31
31
  end
32
32
  rescue ActiveRecord::RecordNotUnique, ActiveRecord::RecordInvalid => error
33
- collision = error.is_a?(ActiveRecord::RecordNotUnique) ||
34
- (error.record.new_record? && error.record.errors.details[:kind].any? { |detail| detail[:error] == :taken })
35
- raise unless collision
33
+ # A concurrent first write can commit between the two uniqueness checks, so only the slug reports taken.
34
+ collision = error.is_a?(ActiveRecord::RecordNotUnique) || (error.record.new_record? &&
35
+ %i[kind slug].any? { |field| error.record.errors.of_kind?(field, :taken) })
36
36
  attempts += 1
37
- retry if attempts == 1
38
- raise Error::ValidationFailed.new(details: [ "kind" ])
37
+ retry if collision && attempts == 1
38
+ raise
39
39
  end
40
40
  render json: PageSerializer.call(page, base_url: request.base_url), status: created ? :created : :ok
41
41
  end
@@ -11,7 +11,9 @@ module OpenBlog
11
11
  paragraphs = entry[:answer].to_s.gsub(/\r\n?/, "\n").split(/\n[\t ]*\n+/).map do |paragraph|
12
12
  tag.p(safe_join(paragraph.split("\n", -1).map { |line| open_blog_faq_links(line) }, safe_join([ tag.br, "\n" ])))
13
13
  end
14
- tag.div(safe_join([ question, *paragraphs ], "\n"), class: "ob-faq-entry", data: { open_blog_faq_entry: true })
14
+ collapsed = OpenBlog.config.faq_collapsed
15
+ content_tag(collapsed ? :details : :div, safe_join([ collapsed ? tag.summary(question) : question, *paragraphs ], "\n"),
16
+ class: "ob-faq-entry", data: { open_blog_faq_entry: true })
15
17
  end
16
18
  tag.section(safe_join([ heading, *items ], "\n"), class: "ob-faq", data: { open_blog_faq: true })
17
19
  end
@@ -7,7 +7,8 @@ module OpenBlog
7
7
  end
8
8
 
9
9
  def open_blog_theme_attributes
10
- open_blog_fixed_theme ? { data: { theme: open_blog_fixed_theme } } : {}
10
+ data = { theme: open_blog_fixed_theme, ob_theme: open_blog_preset&.name&.to_s }.compact
11
+ data.any? ? { data: data } : {}
11
12
  end
12
13
 
13
14
  def open_blog_theme_script
@@ -25,19 +26,42 @@ module OpenBlog
25
26
  end
26
27
 
27
28
  def open_blog_theme_colors
28
- safe_join(SURFACES.map do |scheme, surface|
29
- tag.meta(name: "theme-color", media: "(prefers-color-scheme: #{scheme})", content: SURFACES.fetch(open_blog_fixed_theme, surface))
29
+ preset = open_blog_preset
30
+ surfaces = SURFACES.to_h do |scheme, surface|
31
+ [ scheme, preset ? preset.public_send(scheme).merge(OpenBlog.config.theme_colors_for(scheme.to_sym)).fetch("surface") : surface ]
32
+ end
33
+ safe_join(surfaces.map do |scheme, surface|
34
+ tag.meta(name: "theme-color", media: "(prefers-color-scheme: #{scheme})", content: surfaces.fetch(open_blog_fixed_theme, surface))
30
35
  end, "\n")
31
36
  end
32
37
 
33
38
  def open_blog_stylesheets
34
- stylesheets = [ stylesheet_link_tag("open_blog/blog") ]
39
+ stylesheets = [ open_blog_preset_stylesheet, stylesheet_link_tag("open_blog/blog") ]
35
40
  stylesheets << stylesheet_link_tag("open_blog_theme") if open_blog_theme_override?
36
- safe_join(stylesheets, "\n")
41
+ safe_join([ *stylesheets, open_blog_theme_color_overrides ].compact, "\n")
42
+ end
43
+
44
+ def open_blog_theme_stylesheets
45
+ safe_join([ open_blog_preset_stylesheet, open_blog_theme_color_overrides ].compact, "\n")
37
46
  end
38
47
 
39
48
  private
40
49
 
50
+ def open_blog_preset
51
+ Themes.fetch(OpenBlog.config.theme) unless OpenBlog.config.theme == :none
52
+ end
53
+
54
+ def open_blog_preset_stylesheet
55
+ stylesheet_link_tag("open_blog/themes") if open_blog_preset
56
+ end
57
+
58
+ def open_blog_theme_color_overrides
59
+ return unless open_blog_preset
60
+ colors = Configuration::THEME_MODES.index_with { |mode| OpenBlog.config.theme_colors_for(mode) }
61
+ css = Themes.css(open_blog_preset.name, **colors)
62
+ tag.style(css.html_safe, nonce: content_security_policy_nonce, data: { open_blog_theme_colors: true }) if css.present?
63
+ end
64
+
41
65
  def open_blog_theme_override?
42
66
  assets = Rails.application.assets if Rails.application.respond_to?(:assets)
43
67
  if assets.respond_to?(:resolver)
@@ -44,12 +44,12 @@ module OpenBlog
44
44
  def copy_reader_views(css: css_setup, javascript: javascript_setup)
45
45
  directory "views/open_blog", "app/views/open_blog", **copy_options
46
46
  content = File.read(find_in_source_paths("views/layouts/open_blog.html.erb"))
47
- stylesheet = case css
48
- when :rails then 'stylesheet_link_tag "tailwind", "data-turbo-track": "reload"'
49
- when :bundler then 'stylesheet_link_tag "application", "data-turbo-track": "reload"'
50
- else "open_blog_stylesheets"
47
+ asset = { rails: "tailwind", bundler: "application" }[css]
48
+ if asset
49
+ content = content.sub(/^(\s*)<%= open_blog_stylesheets %>/) do
50
+ "#{$1}<%= open_blog_theme_stylesheets %>\n#{$1}<%= stylesheet_link_tag #{asset.dump}, \"data-turbo-track\": \"reload\" %>"
51
+ end
51
52
  end
52
- content = content.sub("open_blog_stylesheets", stylesheet)
53
53
  if javascript == :bundler
54
54
  content = content.sub("javascript_importmap_tags", 'javascript_include_tag "application", "data-turbo-track": "reload", defer: true')
55
55
  end
@@ -18,8 +18,15 @@ module OpenBlog
18
18
  class_option :skip_sample, type: :boolean, default: false
19
19
  class_option :skip_migrate, type: :boolean, default: false
20
20
  class_option :admin_suite, type: :boolean, default: false
21
+ class_option :theme, type: :string, desc: "Theme preset: #{OpenBlog::Themes.names.join(', ')} (default: signal)"
22
+
23
+ INITIALIZER = "config/initializers/open_blog.rb".freeze
24
+ THEME_SETTING = /^([ \t]*)config\.theme[ \t]*=[ \t]*(?::(\w+))?[^\n]*$/
21
25
 
22
26
  def detect
27
+ unless options[:theme].nil? || OpenBlog::Themes.names.map(&:to_s).include?(options[:theme])
28
+ raise Thor::Error, "--theme must be #{OpenBlog::Themes.names.to_sentence(last_word_connector: ' or ', two_words_connector: ' or ')}"
29
+ end
23
30
  unless %w[markdown rich_text both].include?(options[:body_format])
24
31
  raise Thor::Error, "--body-format must be markdown, rich_text or both"
25
32
  end
@@ -44,7 +51,10 @@ module OpenBlog
44
51
  def configure_blog
45
52
  @site_name = identity(:site_name, "Site name", "Example")
46
53
  @author_name = identity(:author_name, "Author name", "Ada Example")
47
- template "initializer.rb.tt", "config/initializers/open_blog.rb", **copy_options
54
+ @theme = options[:theme] || host_read(INITIALIZER)[THEME_SETTING, 2] || "signal"
55
+ template "initializer.rb.tt", INITIALIZER, **copy_options
56
+ choose_theme if options[:theme]
57
+ say "Theme: #{@theme}"
48
58
  end
49
59
 
50
60
  def install_dependencies
@@ -167,6 +177,17 @@ module OpenBlog
167
177
  success
168
178
  end
169
179
 
180
+ def choose_theme
181
+ setting = "config.theme = :#{@theme}"
182
+ if host_read(INITIALIZER).match?(THEME_SETTING)
183
+ gsub_file INITIALIZER, THEME_SETTING, "\\1#{setting}"
184
+ elsif host_read(INITIALIZER).match?(/^OpenBlog\.configure do \|config\|\n/)
185
+ inject_into_file INITIALIZER, " #{setting}\n", after: /^OpenBlog\.configure do \|config\|\n/
186
+ elsif !options[:pretend]
187
+ raise Thor::Error, "Cannot locate the OpenBlog.configure block; set #{setting} in #{INITIALIZER}."
188
+ end
189
+ end
190
+
170
191
  def identity(key, prompt, placeholder)
171
192
  return options[key] if options[key].present?
172
193
  return ask("#{prompt}:", default: placeholder) if $stdin.tty?
@@ -6,6 +6,7 @@ OpenBlog.configure do |config|
6
6
  config.mount_path = <%= options[:mount_at].dump %>
7
7
  config.body_formats = [ <%= body_formats.map { |format| ":#{format}" }.join(", ") %> ]
8
8
  config.default_body_format = <%= ":#{body_formats.first}" %>
9
+ config.theme = :<%= @theme %>
9
10
  config.primary_list_type = :categories
10
11
  config.sign_in_destinations = []
11
12
  config.ai_label = :when_required