social_construct 0.2.0 → 0.3.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.
- checksums.yaml +4 -4
- data/README.md +4 -5
- data/app/controllers/concerns/social_construct/controller.rb +7 -10
- data/app/controllers/social_construct/previews_controller.rb +27 -14
- data/app/models/social_construct/base_card.rb +1 -1
- data/config/routes.rb +2 -0
- data/lib/generators/social_construct/install/install_generator.rb +1 -5
- data/lib/generators/social_construct/install/templates/example_social_card.html.erb +13 -19
- data/lib/generators/social_construct/install/templates/example_social_card.rb +1 -3
- data/lib/generators/social_construct/install/templates/example_social_card_preview.rb +0 -29
- data/lib/generators/social_construct/install/templates/social_cards_layout.html.erb +7 -7
- data/lib/generators/social_construct/install/templates/social_construct.rb +8 -1
- data/lib/social_construct/engine.rb +7 -5
- data/lib/social_construct/version.rb +1 -1
- data/lib/social_construct.rb +0 -3
- metadata +1 -2
- data/lib/generators/social_construct/install/templates/POST_INSTALL +0 -34
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b1b86abf2f0675a09e15f221cbd4cbda23fbd5f5b37d0406130c30808e3f127
|
4
|
+
data.tar.gz: 5069906dc7297bddd8600b3bef4b321881c09e475138f63980cea760e0e4ff71
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a921f74dd5276deef7b2fc446ccfda8adf15d092ff9e2f43fb48c454f7487a4079286b9bf4a3a3346625aaa95716d956229a73f6dce8a4261fa1a0ffbbc7785b
|
7
|
+
data.tar.gz: 84b6f50e3d7a6fa73432304be9ded5dfb08f47c72f0c30d72b56e779c9ec0f1c73de02db0799f9582f6e94ecdfc6f28409e48247f3f4e6afd32cf171a7e4a667
|
data/README.md
CHANGED
@@ -19,7 +19,7 @@ class PostSocialCard < ApplicationSocialCard
|
|
19
19
|
{
|
20
20
|
title: @post.title,
|
21
21
|
author: @post.author_name,
|
22
|
-
avatar:
|
22
|
+
avatar: attachment_data_url(@post.author.avatar)
|
23
23
|
}
|
24
24
|
end
|
25
25
|
end
|
@@ -70,8 +70,8 @@ Convert ActiveStorage attachments to Base64 `data://` URLs:
|
|
70
70
|
```ruby
|
71
71
|
def template_assigns
|
72
72
|
{
|
73
|
-
cover_image:
|
74
|
-
avatar:
|
73
|
+
cover_image: attachment_data_url(@post.cover_image),
|
74
|
+
avatar: attachment_data_url(@post.author.avatar, resize_to_limit: [200, 200])
|
75
75
|
}
|
76
76
|
end
|
77
77
|
```
|
@@ -134,7 +134,7 @@ end
|
|
134
134
|
Create preview classes:
|
135
135
|
|
136
136
|
```ruby
|
137
|
-
#
|
137
|
+
# test/social_cards/previews/post_social_card_preview.rb
|
138
138
|
class PostSocialCardPreview
|
139
139
|
def default
|
140
140
|
PostSocialCard.new(Post.first)
|
@@ -152,4 +152,3 @@ Visit `http://localhost:3000/rails/social_cards` to preview all cards.
|
|
152
152
|
## License
|
153
153
|
|
154
154
|
MIT
|
155
|
-
|
@@ -3,7 +3,6 @@ module SocialConstruct
|
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
5
|
included do
|
6
|
-
# Register social card mime type if not already registered
|
7
6
|
Mime::Type.register "image/png", :png unless Mime[:png]
|
8
7
|
end
|
9
8
|
|
@@ -35,16 +34,14 @@ module SocialConstruct
|
|
35
34
|
|
36
35
|
# Allow using render with social cards
|
37
36
|
def render(*args)
|
38
|
-
|
39
|
-
card = args.first
|
40
|
-
options = args.second || {}
|
37
|
+
return super unless args.first.is_a?(SocialConstruct::BaseCard)
|
41
38
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
39
|
+
card = args.first
|
40
|
+
options = args.second || {}
|
41
|
+
|
42
|
+
respond_to do |format|
|
43
|
+
format.png { send_social_card(card, **options) }
|
44
|
+
format.html { render(html: card.render.html_safe, layout: false) }
|
48
45
|
end
|
49
46
|
end
|
50
47
|
|
@@ -1,5 +1,9 @@
|
|
1
1
|
module SocialConstruct
|
2
2
|
class PreviewsController < ActionController::Base
|
3
|
+
include SocialConstruct::Controller
|
4
|
+
|
5
|
+
before_action :ensure_previews_enabled
|
6
|
+
|
3
7
|
def index
|
4
8
|
@preview_classes = find_preview_classes
|
5
9
|
end
|
@@ -27,26 +31,29 @@ module SocialConstruct
|
|
27
31
|
|
28
32
|
@card = preview_class.new.send(example_name)
|
29
33
|
|
30
|
-
|
31
|
-
format.html { render(html: @card.render.html_safe, layout: false) }
|
32
|
-
format.png { send_data(@card.to_png, type: "image/png", disposition: "inline") }
|
33
|
-
end
|
34
|
+
render(@card)
|
34
35
|
end
|
35
36
|
|
36
37
|
private
|
37
38
|
|
38
39
|
def find_preview_classes
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
40
|
+
return [] unless (paths = Rails.application.config.social_construct.preview_paths)
|
41
|
+
|
42
|
+
paths
|
43
|
+
.map do |path|
|
44
|
+
next [] unless path.exist?
|
45
|
+
|
46
|
+
glob = path.join("*_preview.rb")
|
47
|
+
|
48
|
+
Dir[glob]
|
49
|
+
.map do |file|
|
50
|
+
require_dependency(file)
|
51
|
+
class_name = File.basename(file, ".rb").camelize
|
52
|
+
class_name.constantize if Object.const_defined?(class_name)
|
53
|
+
end
|
54
|
+
.compact
|
48
55
|
end
|
49
|
-
.
|
56
|
+
.flatten
|
50
57
|
end
|
51
58
|
|
52
59
|
def find_preview_class(name)
|
@@ -57,5 +64,11 @@ module SocialConstruct
|
|
57
64
|
rescue NameError
|
58
65
|
nil
|
59
66
|
end
|
67
|
+
|
68
|
+
def ensure_previews_enabled
|
69
|
+
unless Rails.application.config.social_construct.show_previews
|
70
|
+
raise ActionController::RoutingError, "Social card previews are disabled"
|
71
|
+
end
|
72
|
+
end
|
60
73
|
end
|
61
74
|
end
|
data/config/routes.rb
CHANGED
@@ -28,7 +28,7 @@ module SocialConstruct
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def create_example_preview
|
31
|
-
template("example_social_card_preview.rb", "
|
31
|
+
template("example_social_card_preview.rb", "test/social_cards/previews/example_social_card_preview.rb")
|
32
32
|
end
|
33
33
|
|
34
34
|
def add_route
|
@@ -42,10 +42,6 @@ module SocialConstruct
|
|
42
42
|
|
43
43
|
route(route_string)
|
44
44
|
end
|
45
|
-
|
46
|
-
def display_post_install
|
47
|
-
readme("POST_INSTALL") if behavior == :invoke
|
48
|
-
end
|
49
45
|
end
|
50
46
|
end
|
51
47
|
end
|
@@ -1,7 +1,7 @@
|
|
1
|
-
|
1
|
+
<%% content_for :head do %>
|
2
2
|
<style>
|
3
3
|
body {
|
4
|
-
background-color:
|
4
|
+
background-color: <%%= background_color %>;
|
5
5
|
display: flex;
|
6
6
|
align-items: center;
|
7
7
|
justify-content: center;
|
@@ -9,11 +9,11 @@
|
|
9
9
|
text-align: center;
|
10
10
|
padding: 60px;
|
11
11
|
}
|
12
|
-
|
12
|
+
|
13
13
|
.content {
|
14
14
|
max-width: 900px;
|
15
15
|
}
|
16
|
-
|
16
|
+
|
17
17
|
.title {
|
18
18
|
font-size: 72px;
|
19
19
|
font-weight: 800;
|
@@ -21,26 +21,26 @@
|
|
21
21
|
margin-bottom: 24px;
|
22
22
|
letter-spacing: -2px;
|
23
23
|
}
|
24
|
-
|
24
|
+
|
25
25
|
.subtitle {
|
26
26
|
font-size: 32px;
|
27
27
|
font-weight: 400;
|
28
28
|
opacity: 0.8;
|
29
29
|
line-height: 1.3;
|
30
30
|
}
|
31
|
-
|
31
|
+
|
32
32
|
.logo {
|
33
33
|
position: absolute;
|
34
34
|
bottom: 60px;
|
35
35
|
right: 60px;
|
36
36
|
}
|
37
|
-
|
37
|
+
|
38
38
|
.logo img {
|
39
39
|
height: 40px;
|
40
40
|
width: auto;
|
41
41
|
opacity: 0.9;
|
42
42
|
}
|
43
|
-
|
43
|
+
|
44
44
|
.decoration {
|
45
45
|
position: absolute;
|
46
46
|
top: 0;
|
@@ -51,19 +51,13 @@
|
|
51
51
|
pointer-events: none;
|
52
52
|
}
|
53
53
|
</style>
|
54
|
-
|
54
|
+
<%% end %>
|
55
55
|
|
56
56
|
<div class="decoration"></div>
|
57
57
|
|
58
58
|
<div class="content">
|
59
|
-
<h1 class="title"
|
60
|
-
|
61
|
-
<p class="subtitle"
|
62
|
-
|
59
|
+
<h1 class="title"><%%= title %></h1>
|
60
|
+
<%% if subtitle.present? %>
|
61
|
+
<p class="subtitle"><%%= subtitle %></p>
|
62
|
+
<%% end %>
|
63
63
|
</div>
|
64
|
-
|
65
|
-
<% if logo_data_url %>
|
66
|
-
<div class="logo">
|
67
|
-
<img src="<%= logo_data_url %>" alt="Logo">
|
68
|
-
</div>
|
69
|
-
<% end %>
|
@@ -1,6 +1,5 @@
|
|
1
1
|
class ExampleSocialCard < ApplicationSocialCard
|
2
2
|
def initialize(title: "Hello World", subtitle: nil, background_color: "#1a1a1a")
|
3
|
-
super()
|
4
3
|
@title = title
|
5
4
|
@subtitle = subtitle
|
6
5
|
@background_color = background_color
|
@@ -12,8 +11,7 @@ class ExampleSocialCard < ApplicationSocialCard
|
|
12
11
|
{
|
13
12
|
title: @title,
|
14
13
|
subtitle: @subtitle,
|
15
|
-
background_color: @background_color
|
16
|
-
logo_data_url: logo_data_url
|
14
|
+
background_color: @background_color
|
17
15
|
}
|
18
16
|
end
|
19
17
|
end
|
@@ -5,33 +5,4 @@ class ExampleSocialCardPreview
|
|
5
5
|
subtitle: "Beautiful social cards for your Rails app"
|
6
6
|
)
|
7
7
|
end
|
8
|
-
|
9
|
-
def dark_theme
|
10
|
-
ExampleSocialCard.new(
|
11
|
-
title: "Dark Theme Example",
|
12
|
-
subtitle: "Perfect for modern applications",
|
13
|
-
background_color: "#0a0a0a"
|
14
|
-
)
|
15
|
-
end
|
16
|
-
|
17
|
-
def colorful
|
18
|
-
ExampleSocialCard.new(
|
19
|
-
title: "Colorful Background",
|
20
|
-
subtitle: "Make your cards stand out",
|
21
|
-
background_color: "#6366f1"
|
22
|
-
)
|
23
|
-
end
|
24
|
-
|
25
|
-
def long_title
|
26
|
-
ExampleSocialCard.new(
|
27
|
-
title: "This is a very long title that demonstrates how text wrapping works in social cards",
|
28
|
-
subtitle: "Subtitle remains readable"
|
29
|
-
)
|
30
|
-
end
|
31
|
-
|
32
|
-
def no_subtitle
|
33
|
-
ExampleSocialCard.new(
|
34
|
-
title: "Simple and Clean"
|
35
|
-
)
|
36
|
-
end
|
37
8
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
<!DOCTYPE html>
|
2
|
-
<html lang="
|
2
|
+
<html lang="<%%= I18n.locale %>">
|
3
3
|
<head>
|
4
4
|
<meta charset="utf-8">
|
5
5
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
@@ -10,13 +10,13 @@
|
|
10
10
|
padding: 0;
|
11
11
|
box-sizing: border-box;
|
12
12
|
}
|
13
|
-
|
13
|
+
|
14
14
|
html {
|
15
15
|
width: 1200px;
|
16
16
|
height: 630px;
|
17
17
|
background: white;
|
18
18
|
}
|
19
|
-
|
19
|
+
|
20
20
|
body {
|
21
21
|
width: 1200px;
|
22
22
|
height: 630px;
|
@@ -28,23 +28,23 @@
|
|
28
28
|
-webkit-font-smoothing: antialiased;
|
29
29
|
-moz-osx-font-smoothing: grayscale;
|
30
30
|
}
|
31
|
-
|
31
|
+
|
32
32
|
/* Ensure images don't have borders */
|
33
33
|
img {
|
34
34
|
border: 0;
|
35
35
|
max-width: 100%;
|
36
36
|
}
|
37
|
-
|
37
|
+
|
38
38
|
/* Default text rendering */
|
39
39
|
h1, h2, h3, h4, h5, h6, p {
|
40
40
|
font-weight: normal;
|
41
41
|
margin: 0;
|
42
42
|
}
|
43
43
|
</style>
|
44
|
-
|
44
|
+
<%%= yield :head %>
|
45
45
|
</head>
|
46
46
|
<body>
|
47
|
-
|
47
|
+
<%%= yield %>
|
48
48
|
</body>
|
49
49
|
</html>
|
50
50
|
|
@@ -1,9 +1,16 @@
|
|
1
|
-
# SocialConstruct configuration
|
2
1
|
Rails.application.configure do
|
3
2
|
# Configure the template path for social card views
|
4
3
|
# Default: "social_cards"
|
5
4
|
# config.social_construct.template_path = "social_cards"
|
6
5
|
|
6
|
+
# Configure paths for social card previews
|
7
|
+
# Default: ["test/social_cards/previews"]
|
8
|
+
# config.social_construct.preview_paths = ["test/social_cards/previews"]
|
9
|
+
|
10
|
+
# Enable social card previews
|
11
|
+
# Default: true in development, false otherwise
|
12
|
+
# config.social_construct.show_previews = Rails.env.development?
|
13
|
+
|
7
14
|
# Enable debug logging for social card generation
|
8
15
|
# Default: false
|
9
16
|
# SocialConstruct::BaseCard.debug = true
|
@@ -4,12 +4,14 @@ module SocialConstruct
|
|
4
4
|
|
5
5
|
config.social_construct = ActiveSupport::OrderedOptions.new
|
6
6
|
config.social_construct.template_path = "social_cards"
|
7
|
+
config.social_construct.preview_paths = []
|
8
|
+
config.social_construct.show_previews = Rails.env.development?
|
7
9
|
|
8
|
-
#
|
9
|
-
config.
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
# Set default preview path after application initializes
|
11
|
+
config.after_initialize do |app|
|
12
|
+
if app.config.social_construct.preview_paths.empty?
|
13
|
+
app.config.social_construct.preview_paths = [Rails.root.join("test/social_cards/previews")]
|
14
|
+
end
|
13
15
|
end
|
14
16
|
end
|
15
17
|
end
|
data/lib/social_construct.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: social_construct
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mikkel Malmberg
|
@@ -68,7 +68,6 @@ files:
|
|
68
68
|
- app/views/social_construct/previews/show.html.erb
|
69
69
|
- config/routes.rb
|
70
70
|
- lib/generators/social_construct/install/install_generator.rb
|
71
|
-
- lib/generators/social_construct/install/templates/POST_INSTALL
|
72
71
|
- lib/generators/social_construct/install/templates/application_social_card.rb
|
73
72
|
- lib/generators/social_construct/install/templates/example_social_card.html.erb
|
74
73
|
- lib/generators/social_construct/install/templates/example_social_card.rb
|
@@ -1,34 +0,0 @@
|
|
1
|
-
===============================================================================
|
2
|
-
|
3
|
-
SocialConstruct has been successfully installed! 🎉
|
4
|
-
|
5
|
-
Next steps:
|
6
|
-
|
7
|
-
1. Update the logo path in app/social_cards/application_social_card.rb
|
8
|
-
to point to your actual logo file.
|
9
|
-
|
10
|
-
2. Run your Rails server and visit:
|
11
|
-
http://localhost:3000/rails/social_cards
|
12
|
-
|
13
|
-
You should see the example social card previews.
|
14
|
-
|
15
|
-
3. Create your own social card classes:
|
16
|
-
- Inherit from ApplicationSocialCard
|
17
|
-
- Create matching templates in app/views/social_cards/
|
18
|
-
- Add preview classes in app/social_cards/previews/
|
19
|
-
|
20
|
-
4. Use in your controllers:
|
21
|
-
|
22
|
-
class YourController < ApplicationController
|
23
|
-
include SocialConstruct::Controller
|
24
|
-
|
25
|
-
def og
|
26
|
-
@model = Model.find(params[:id])
|
27
|
-
render YourSocialCard.new(@model)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
For more information, see:
|
32
|
-
https://github.com/brnbw/social_construct
|
33
|
-
|
34
|
-
===============================================================================
|