social_linker 0.2 → 0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f8d3e93ca4d88de3fdd12f5d738a9af7e7a68627
4
- data.tar.gz: 43d0897a189edf1e5ebf1ac4d41d199ef067759a
3
+ metadata.gz: 5c3db60b8186c8555f88a031d0bb93228630dc27
4
+ data.tar.gz: 10b7a36a98551d9d017b3b089cc28af4594f3b70
5
5
  SHA512:
6
- metadata.gz: d4e08bec4223c51baa898f72185818a62139d29d57847624ca0dd7ee4112ba92fee5269be271e751eeee40188d45f04f139c19d06e5cf97a6ae99f7fc05a6fe3
7
- data.tar.gz: 762b1cf66474bdb86821c514564c9ad2b584d28fb3676faf58b29a61a414c35ed2d6c9faed05df16afa94d26532e76d5837799ee49ce6c7424ab0cfbb43ea6ab
6
+ metadata.gz: 8e16b1ef40ad811b71d2de74112f7490724b46276022ee1ea46da7b6fb590dd7896bd0a9a7a48686624cc6afaf692a67cd27fd70c4a84d4db27015ef92190721
7
+ data.tar.gz: 6c4f099066e9dcbc0b804a2329402edb3b9a0facb13b5777727fbaf65886da7288027e95ba081ebca588f97d518cf014e5a27f98cf7ea0bccd6e7f64814ac353
data/README.md CHANGED
@@ -101,11 +101,48 @@ Just set the following, which should give you a reasonable default.
101
101
  site_title_postfix: "your sitename" # optional
102
102
  })
103
103
 
104
+ ### Link helper with SVG icons
105
+
106
+ Use the following to create a sharelink to Facebook
107
+
108
+ social_link_to @subject, :facebook
109
+
110
+ This results in a simple `<a href>` containing the share link and an svg image.
111
+ This SVG image may or may not be found depending on your asset initialization,
112
+ make sure that config/initializers/assets.rb contains the following line:
113
+
114
+ Rails.application.config.assets.precompile += %w( social_linker/icons.svg )
115
+
116
+ (if you don't it probably will be suggested to you by Rails)
117
+
118
+ If you want to change the content of the link, pass a block, e.g.:
119
+
120
+ social_link_to @subject, :facebook do
121
+ "Share on Facebook!"
122
+ end
123
+
124
+ To make sure that the icons align well, make sure to include the styling, include
125
+ the following line to the head of your application.ccs file:
126
+
127
+ *= require social_linker/icons
128
+
129
+ #### Tip: SVG4Everyone
130
+
131
+ When using SVG and serving your pages to older browsers, make sure you use something
132
+ like SVG4Everyone. Include in your gemfile:
133
+
134
+ source 'https://rails-assets.org' do
135
+ gem 'rails-assets-svg4everybody'
136
+ end
137
+
138
+ and include the following line to the head of your `application.js` file:
139
+
140
+ //= require svg4everybody
141
+
104
142
  ## TODO
105
143
 
106
- * Render sharelink helpers (including SVG icons)
107
- * [Further improvement] include even [javascript timeout workarounds](http://stackoverflow.com/questions/7231085/how-to-fall-back-to-marketplace-when-android-custom-url-scheme-not-handled)
108
- * More share methods!
144
+ * Idea: maybe improve share helpers with [javascript timeout workarounds](http://stackoverflow.com/questions/7231085/how-to-fall-back-to-marketplace-when-android-custom-url-scheme-not-handled) for native alternatives (although Twitter and facebook work well)
145
+ * More share methods (pull request welcome)
109
146
 
110
147
  ## Development
111
148
 
@@ -0,0 +1,56 @@
1
+ <svg style="position: absolute; width: 0; height: 0;" width="0" height="0" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
2
+ <defs>
3
+ <symbol id="icon-email" viewBox="0 0 32 32">
4
+ <title>email</title>
5
+ <path class="path1" d="M32 12.679v14.179q0 1.179-0.839 2.018t-2.018 0.839h-26.286q-1.179 0-2.018-0.839t-0.839-2.018v-14.179q0.786 0.875 1.804 1.554 6.464 4.393 8.875 6.161 1.018 0.75 1.652 1.17t1.688 0.857 1.964 0.438h0.036q0.911 0 1.964-0.438t1.688-0.857 1.652-1.17q3.036-2.196 8.893-6.161 1.018-0.696 1.786-1.554zM32 7.429q0 1.411-0.875 2.696t-2.179 2.196q-6.714 4.661-8.357 5.804-0.179 0.125-0.759 0.545t-0.964 0.679-0.929 0.58-1.027 0.482-0.893 0.161h-0.036q-0.411 0-0.893-0.161t-1.027-0.482-0.929-0.58-0.964-0.679-0.759-0.545q-1.625-1.143-4.679-3.259t-3.661-2.545q-1.107-0.75-2.089-2.063t-0.982-2.438q0-1.393 0.741-2.321t2.116-0.929h26.286q1.161 0 2.009 0.839t0.848 2.018z"></path>
6
+ </symbol>
7
+ <symbol id="icon-google" viewBox="0 0 27 32">
8
+ <title>google</title>
9
+ <path class="path1" d="M13.714 14.036h12.946q0.214 1.196 0.214 2.286 0 3.875-1.625 6.92t-4.634 4.759-6.902 1.714q-2.804 0-5.339-1.080t-4.375-2.92-2.92-4.375-1.080-5.339 1.080-5.339 2.92-4.375 4.375-2.92 5.339-1.080q5.357 0 9.196 3.589l-3.732 3.589q-2.196-2.125-5.464-2.125-2.304 0-4.259 1.161t-3.098 3.152-1.143 4.348 1.143 4.348 3.098 3.152 4.259 1.161q1.554 0 2.857-0.429t2.143-1.071 1.464-1.464 0.92-1.554 0.402-1.393h-7.786v-4.714z"></path>
10
+ </symbol>
11
+ <symbol id="icon-sticky-note-o" viewBox="0 0 27 32">
12
+ <title>sticky-note-o</title>
13
+ <path class="path1" d="M25 22.857h-4.429v4.429q0.518-0.179 0.732-0.393l3.304-3.304q0.214-0.214 0.393-0.732zM20 20.571h5.143v-16h-22.857v22.857h16v-5.143q0-0.714 0.5-1.214t1.214-0.5zM27.429 4v18.286q0 0.714-0.357 1.571t-0.857 1.357l-3.286 3.286q-0.5 0.5-1.357 0.857t-1.571 0.357h-18.286q-0.714 0-1.214-0.5t-0.5-1.214v-24q0-0.714 0.5-1.214t1.214-0.5h24q0.714 0 1.214 0.5t0.5 1.214z"></path>
14
+ </symbol>
15
+ <symbol id="icon-share-square-o" viewBox="0 0 30 32">
16
+ <title>share-square-o</title>
17
+ <path class="path1" d="M25.143 17.661v4.625q0 2.125-1.509 3.634t-3.634 1.509h-14.857q-2.125 0-3.634-1.509t-1.509-3.634v-14.857q0-2.125 1.509-3.634t3.634-1.509h4.554q0.232 0 0.402 0.17t0.17 0.402q0 0.482-0.464 0.571-1.375 0.464-2.375 1.071-0.179 0.071-0.286 0.071h-2q-1.179 0-2.018 0.839t-0.839 2.018v14.857q0 1.179 0.839 2.018t2.018 0.839h14.857q1.179 0 2.018-0.839t0.839-2.018v-3.821q0-0.339 0.321-0.518 0.5-0.232 0.964-0.661 0.286-0.286 0.625-0.143 0.375 0.161 0.375 0.518zM29.375 8.804l-6.857 6.857q-0.321 0.339-0.804 0.339-0.214 0-0.446-0.089-0.696-0.304-0.696-1.054v-3.429h-2.857q-5.768 0-7.821 2.339-2.125 2.446-1.321 8.446 0.054 0.411-0.357 0.607-0.143 0.036-0.214 0.036-0.286 0-0.464-0.232-0.179-0.25-0.375-0.554t-0.705-1.223-0.884-1.777-0.688-2.036-0.313-2.179q0-0.875 0.063-1.625t0.25-1.607 0.5-1.571 0.839-1.455 1.223-1.321 1.687-1.098 2.223-0.866 2.848-0.545 3.509-0.196h2.857v-3.429q0-0.75 0.696-1.054 0.232-0.089 0.446-0.089 0.464 0 0.804 0.339l6.857 6.857q0.339 0.339 0.339 0.804t-0.339 0.804z"></path>
18
+ </symbol>
19
+ <symbol id="icon-search" viewBox="0 0 30 32">
20
+ <title>search</title>
21
+ <path class="path1" d="M20.571 14.857q0-3.304-2.348-5.652t-5.652-2.348-5.652 2.348-2.348 5.652 2.348 5.652 5.652 2.348 5.652-2.348 2.348-5.652zM29.714 29.714q0 0.929-0.679 1.607t-1.607 0.679q-0.964 0-1.607-0.679l-6.125-6.107q-3.196 2.214-7.125 2.214-2.554 0-4.884-0.991t-4.018-2.679-2.679-4.018-0.991-4.884 0.991-4.884 2.679-4.018 4.018-2.679 4.884-0.991 4.884 0.991 4.018 2.679 2.679 4.018 0.991 4.884q0 3.929-2.214 7.125l6.125 6.125q0.661 0.661 0.661 1.607z"></path>
22
+ </symbol>
23
+ <symbol id="icon-heart-o" viewBox="0 0 32 32">
24
+ <title>heart-o</title>
25
+ <path class="path1" d="M29.714 10.643q0-1.446-0.384-2.554t-0.982-1.759-1.455-1.063-1.679-0.554-1.75-0.143-2 0.455-1.973 1.143-1.545 1.286-1.071 1.098q-0.321 0.393-0.875 0.393t-0.875-0.393q-0.429-0.5-1.071-1.098t-1.545-1.286-1.973-1.143-2-0.455-1.75 0.143-1.679 0.554-1.455 1.063-0.982 1.759-0.384 2.554q0 3 3.339 6.339l10.375 10 10.357-9.982q3.357-3.357 3.357-6.357zM32 10.643q0 3.946-4.089 8.036l-11.125 10.714q-0.321 0.321-0.786 0.321t-0.786-0.321l-11.143-10.75q-0.179-0.143-0.491-0.464t-0.991-1.17-1.214-1.741-0.955-2.161-0.42-2.464q0-3.929 2.268-6.143t6.268-2.214q1.107 0 2.259 0.384t2.143 1.036 1.705 1.223 1.357 1.214q0.643-0.643 1.357-1.214t1.705-1.223 2.143-1.036 2.259-0.384q4 0 6.268 2.214t2.268 6.143z"></path>
26
+ </symbol>
27
+ <symbol id="icon-heart" viewBox="0 0 32 32">
28
+ <title>heart</title>
29
+ <path class="path1" d="M16 29.714q-0.464 0-0.786-0.321l-11.143-10.75q-0.179-0.143-0.491-0.464t-0.991-1.17-1.214-1.741-0.955-2.161-0.42-2.464q0-3.929 2.268-6.143t6.268-2.214q1.107 0 2.259 0.384t2.143 1.036 1.705 1.223 1.357 1.214q0.643-0.643 1.357-1.214t1.705-1.223 2.143-1.036 2.259-0.384q4 0 6.268 2.214t2.268 6.143q0 3.946-4.089 8.036l-11.125 10.714q-0.321 0.321-0.786 0.321z"></path>
30
+ </symbol>
31
+ <symbol id="icon-twitter" viewBox="0 0 30 32">
32
+ <title>twitter</title>
33
+ <path class="path1" d="M28.929 7.286q-1.196 1.75-2.893 2.982 0.018 0.25 0.018 0.75 0 2.321-0.679 4.634t-2.063 4.437-3.295 3.759-4.607 2.607-5.768 0.973q-4.839 0-8.857-2.589 0.625 0.071 1.393 0.071 4.018 0 7.161-2.464-1.875-0.036-3.357-1.152t-2.036-2.848q0.589 0.089 1.089 0.089 0.768 0 1.518-0.196-2-0.411-3.313-1.991t-1.313-3.67v-0.071q1.214 0.679 2.607 0.732-1.179-0.786-1.875-2.054t-0.696-2.75q0-1.571 0.786-2.911 2.161 2.661 5.259 4.259t6.634 1.777q-0.143-0.679-0.143-1.321 0-2.393 1.688-4.080t4.080-1.688q2.5 0 4.214 1.821 1.946-0.375 3.661-1.393-0.661 2.054-2.536 3.179 1.661-0.179 3.321-0.893z"></path>
34
+ </symbol>
35
+ <symbol id="icon-pinterest" viewBox="0 0 27 32">
36
+ <title>pinterest</title>
37
+ <path class="path1" d="M27.429 16q0 3.732-1.839 6.884t-4.991 4.991-6.884 1.839q-1.982 0-3.893-0.571 1.054-1.661 1.393-2.929 0.161-0.607 0.964-3.768 0.357 0.696 1.304 1.205t2.036 0.509q2.161 0 3.857-1.223t2.625-3.366 0.929-4.821q0-2.036-1.063-3.821t-3.080-2.911-4.554-1.125q-1.875 0-3.5 0.518t-2.759 1.375-1.946 1.973-1.196 2.313-0.384 2.393q0 1.857 0.714 3.268t2.089 1.982q0.536 0.214 0.679-0.357 0.036-0.125 0.143-0.554t0.143-0.536q0.107-0.411-0.196-0.768-0.911-1.089-0.911-2.696 0-2.696 1.866-4.634t4.884-1.938q2.696 0 4.205 1.464t1.509 3.804q0 3.036-1.223 5.161t-3.134 2.125q-1.089 0-1.75-0.777t-0.411-1.866q0.143-0.625 0.473-1.67t0.536-1.839 0.205-1.348q0-0.893-0.482-1.482t-1.375-0.589q-1.107 0-1.875 1.018t-0.768 2.536q0 1.304 0.446 2.179l-1.768 7.464q-0.304 1.25-0.232 3.161-3.679-1.625-5.946-5.018t-2.268-7.554q0-3.732 1.839-6.884t4.991-4.991 6.884-1.839 6.884 1.839 4.991 4.991 1.839 6.884z"></path>
38
+ </symbol>
39
+ <symbol id="icon-facebook" viewBox="0 0 27 32">
40
+ <title>facebook</title>
41
+ <path class="path1" d="M25.911 2.286q0.625 0 1.071 0.446t0.446 1.071v24.393q0 0.625-0.446 1.071t-1.071 0.446h-6.982v-10.625h3.554l0.536-4.143h-4.089v-2.643q0-1 0.42-1.5t1.634-0.5l2.179-0.018v-3.696q-1.125-0.161-3.179-0.161-2.429 0-3.884 1.429t-1.455 4.036v3.054h-3.571v4.143h3.571v10.625h-13.125q-0.625 0-1.071-0.446t-0.446-1.071v-24.393q0-0.625 0.446-1.071t1.071-0.446h24.393z"></path>
42
+ </symbol>
43
+ <symbol id="icon-linkedin" viewBox="0 0 27 32">
44
+ <title>linkedin</title>
45
+ <path class="path1" d="M6.232 11.161v17.696h-5.893v-17.696h5.893zM6.607 5.696q0.018 1.304-0.902 2.179t-2.42 0.875h-0.036q-1.464 0-2.357-0.875t-0.893-2.179q0-1.321 0.92-2.188t2.402-0.866 2.375 0.866 0.911 2.188zM27.429 18.714v10.143h-5.875v-9.464q0-1.875-0.723-2.938t-2.259-1.063q-1.125 0-1.884 0.616t-1.134 1.527q-0.196 0.536-0.196 1.446v9.875h-5.875q0.036-7.125 0.036-11.554t-0.018-5.286l-0.018-0.857h5.875v2.571h-0.036q0.357-0.571 0.732-1t1.009-0.929 1.554-0.777 2.045-0.277q3.054 0 4.911 2.027t1.857 5.938z"></path>
46
+ </symbol>
47
+ <symbol id="icon-whatsapp" viewBox="0 0 27 32">
48
+ <title>whatsapp</title>
49
+ <path class="path1" d="M17.589 17.393q0.232 0 1.741 0.786t1.598 0.946q0.036 0.089 0.036 0.268 0 0.589-0.304 1.357-0.286 0.696-1.268 1.17t-1.821 0.473q-1.018 0-3.393-1.107-1.75-0.804-3.036-2.107t-2.643-3.304q-1.286-1.911-1.268-3.464v-0.143q0.054-1.625 1.321-2.821 0.429-0.393 0.929-0.393 0.107 0 0.321 0.027t0.339 0.027q0.339 0 0.473 0.116t0.277 0.491q0.143 0.357 0.589 1.571t0.446 1.339q0 0.375-0.616 1.027t-0.616 0.83q0 0.125 0.089 0.268 0.607 1.304 1.821 2.446 1 0.946 2.696 1.804 0.214 0.125 0.393 0.125 0.268 0 0.964-0.866t0.929-0.866zM13.964 26.857q2.268 0 4.348-0.893t3.58-2.393 2.393-3.58 0.893-4.348-0.893-4.348-2.393-3.58-3.58-2.393-4.348-0.893-4.348 0.893-3.58 2.393-2.393 3.58-0.893 4.348q0 3.625 2.143 6.571l-1.411 4.161 4.321-1.375q2.821 1.857 6.161 1.857zM13.964 2.179q2.732 0 5.223 1.071t4.295 2.875 2.875 4.295 1.071 5.223-1.071 5.223-2.875 4.295-4.295 2.875-5.223 1.071q-3.482 0-6.518-1.679l-7.446 2.393 2.429-7.232q-1.929-3.179-1.929-6.946 0-2.732 1.071-5.223t2.875-4.295 4.295-2.875 5.223-1.071z"></path>
50
+ </symbol>
51
+ <symbol id="icon-tumblr" viewBox="0 0 20 32">
52
+ <title>tumblr</title>
53
+ <path class="path1" d="M16.857 23.732l1.429 4.232q-0.411 0.625-1.982 1.179t-3.161 0.571q-1.857 0.036-3.402-0.464t-2.545-1.321-1.696-1.893-0.991-2.143-0.295-2.107v-9.714h-3v-3.839q1.286-0.464 2.304-1.241t1.625-1.607 1.036-1.821 0.607-1.768 0.268-1.58q0.018-0.089 0.080-0.152t0.134-0.063h4.357v7.571h5.946v4.5h-5.964v9.25q0 0.536 0.116 1t0.402 0.938 0.884 0.741 1.455 0.25q1.393-0.036 2.393-0.518z"></path>
54
+ </symbol>
55
+ </defs>
56
+ </svg>
@@ -0,0 +1,58 @@
1
+ .icon {
2
+ display: inline-block;
3
+ width: 1em;
4
+ height: 1em;
5
+ fill: currentColor;
6
+ &:hover {
7
+ opacity: 0.8
8
+ };
9
+ &.icon-default-style {
10
+ fill: #000;
11
+ }
12
+ }
13
+
14
+ /* =======================================================================================
15
+ Example showing how to change the color/size of the icons:
16
+ .icon-name {
17
+ font-size: 32px; // works because "width" & "height" were set using em units
18
+ color: red; // works for single-colored icons, because "fill" was set to "currentColor"
19
+ }
20
+ ======================================================================================== */
21
+
22
+
23
+ .icon-sticky-note-o {
24
+ width: 0.857421875em;
25
+ }
26
+
27
+ .icon-share-square-o {
28
+ width: 0.9287109375em;
29
+ }
30
+
31
+ .icon-search {
32
+ width: 0.9287109375em;
33
+ }
34
+
35
+ .icon-twitter {
36
+ width: 0.9287109375em;
37
+ }
38
+
39
+ .icon-pinterest {
40
+ width: 0.857421875em;
41
+ }
42
+
43
+ .icon-facebook {
44
+ width: 0.857421875em;
45
+ }
46
+
47
+ .icon-google {
48
+ width: 0.83984375em;
49
+ }
50
+ .icon-linkedin {
51
+ width: 0.857421875em;
52
+ }
53
+ .icon-whatsapp {
54
+ width: 0.857421875em;
55
+ }
56
+ .icon-tumblr {
57
+ width: 0.609375em;
58
+ }
@@ -0,0 +1,106 @@
1
+ module ViewHelpers
2
+ # renders a metatag
3
+ # param [String, Symbol] name (or property) (defaults to name, values starting with 'og:' (opengraph) will be using the property attribute)
4
+ # param [String, Symbol] content (the value for the name or the property)
5
+ # @returns [String, nil] nil is returned when the content is empty
6
+ def meta_tag(name, content)
7
+ name_or_property_section = name.start_with?("og:") ? "property=\"#{erb_sanitized(name)}\"" : "name=\"#{erb_sanitized(name)}\""
8
+ "<meta #{name_or_property_section} content=\"#{erb_sanitized(content)}\" />" if content and content != ""
9
+ end
10
+
11
+ def erb_sanitized(value)
12
+ if defined? Rails
13
+ h(value)
14
+ else
15
+ ERB::Util.h(value)
16
+ end
17
+ end
18
+
19
+ # header_meta_tags renders the most important metatags based on the SocialLinker::Subject
20
+ #
21
+ # @param [SocialLinker::Subject] the SocialLinker::Subject initialized as complete as possible
22
+ # @param [Hash] options with site-defaults for `:site_title_postfix`, (e.g. article title - {site title postfix here}), `:domain` (the main url),
23
+ # @return String of tags (possibly marked as sanitized when available)
24
+ def header_meta_tags subject, options={}
25
+ site_title_postfix = options[:site_title_postfix]
26
+ header_html = []
27
+ if subject
28
+ domain = options[:domain] || subject.options[:domain]
29
+
30
+ header_html << meta_tag("twitter:card", subject.media ? :summary_large_image : :summary)
31
+ header_html << meta_tag("twitter:site", subject.options[:twitter_username])
32
+ header_html << meta_tag("twitter:creator", subject.options[:twitter_username])
33
+ header_html << meta_tag("twitter:domain", domain)
34
+
35
+ if subject.url
36
+ header_html << meta_tag("og:url", subject.canonical_url)
37
+ header_html << "<link rel=\"canonical\" content=\"#{erb_sanitized(subject.canonical_url)}\" />"
38
+ end
39
+
40
+ header_html << meta_tag("keywords", subject.tags.join(" "))
41
+ header_html << meta_tag("description", subject.summary)
42
+
43
+ header_html << meta_tag("twitter:description", subject.summary)
44
+ header_html << meta_tag("og:description", subject.summary)
45
+
46
+ if subject.media
47
+ header_html << meta_tag("twitter:image:src", subject.media)
48
+ header_html << meta_tag("og:image", subject.media)
49
+ header_html << meta_tag("og:image:type", subject.options[:image_type])
50
+ end
51
+ end
52
+
53
+ title = @title
54
+ title = subject.title if subject
55
+ site_title = [title, site_title_postfix].uniq.compact.join(" - ")
56
+ header_html << "<title>#{erb_sanitized(site_title)}</title>"
57
+ header_html << meta_tag("twitter:title", title)
58
+ header_html << meta_tag("og:title", title)
59
+
60
+ header_html.compact!
61
+ header_html = header_html.join("\n") if header_html
62
+
63
+ # we trust the html because all user input is sanitized by erb_sanitized
64
+ header_html = header_html.html_safe if header_html.methods.include?(:html_safe)
65
+ header_html
66
+ end
67
+
68
+ # Generates the <SVG> code for the image
69
+ # It references the parent image path with `xlink:href`. Make sure your browser supports this, or use something like `svg4everyone` to fix your client's browsers
70
+ # Options:
71
+ # * social_icons_image_path (defaults to the default SocialLinker iconset)
72
+ # * title (the title attribute, defaults to the network's name capitalized)
73
+
74
+ def social_link_to_image(network, image_path)
75
+ if network and image_path
76
+ "<svg class=\"icon icon-#{network} icon-default-style\"><use xlink:href=\"#{image_path}#icon-#{network}\"></use></svg>"
77
+ end
78
+ end
79
+
80
+ def social_link_to subject, network, options = {}
81
+ raise ArgumentError, "subject can't be nil" unless subject
82
+ raise ArgumentError, "network can't be nil" unless network
83
+ options_with_defaults = {
84
+ social_icons_image_path: 'social_linker/icons.svg',
85
+ title: network.to_s.capitalize
86
+ }.merge(options)
87
+
88
+ link_content = network
89
+
90
+ if block_given?
91
+ link_content = yield
92
+ else
93
+ social_icons_image_path = options_with_defaults[:social_icons_image_path]
94
+ social_icons_image_path = image_path(social_icons_image_path) if self.methods.include?(:image_path)
95
+
96
+ link_content = social_link_to_image(network, social_icons_image_path)
97
+ end
98
+
99
+ title = options_with_defaults[:title]
100
+
101
+ html = "<a href=\"#{erb_sanitized(subject.share_link(network))}\" class=\"#{network}\" title=\"#{title}\">#{link_content}</a>"
102
+ html = html.html_safe if html.methods.include?(:html_safe)
103
+ html
104
+ end
105
+
106
+ end
data/lib/social_linker.rb CHANGED
@@ -1,11 +1,11 @@
1
1
  require "social_linker/version"
2
2
  require "social_linker/subject"
3
- require 'social_linker/railtie' if defined?(Rails)
4
- # require "ERB"
5
- # include ERB::Util
3
+ require 'social_linker/engine' if defined?(Rails)
4
+
5
+ # SocialLinker
6
6
  #
7
- # module SocialLinker
8
- #
9
- # # The main class of SocialLinker is the `SocialLinker::Subject`-class.
10
- #
11
- # end
7
+ # The SocialLinker namespace contains The SocialLinker::Subject and the
8
+ # SocialSubject::Engine (for Rails projects)
9
+ module SocialLinker
10
+ # The main class of SocialLinker is the `SocialLinker::Subject`-class.
11
+ end
@@ -0,0 +1,8 @@
1
+ module SocialLinker
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace SocialLinker
4
+ config.to_prepare do
5
+ ApplicationController.helper(ViewHelpers)
6
+ end
7
+ end
8
+ end
@@ -1,3 +1,3 @@
1
1
  module SocialLinker
2
- VERSION = "0.2"
2
+ VERSION = "0.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: social_linker
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.2'
4
+ version: '0.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - murb
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-18 00:00:00.000000000 Z
11
+ date: 2016-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -70,13 +70,15 @@ files:
70
70
  - LICENSE.txt
71
71
  - README.md
72
72
  - Rakefile
73
+ - app/assets/images/social_linker/icons.svg
74
+ - app/assets/stylesheets/social_linker/icons.scss
75
+ - app/helpers/view_helpers.rb
73
76
  - bin/console
74
77
  - bin/setup
75
78
  - lib/social_linker.rb
76
- - lib/social_linker/railtie.rb
79
+ - lib/social_linker/engine.rb
77
80
  - lib/social_linker/subject.rb
78
81
  - lib/social_linker/version.rb
79
- - lib/social_linker/view_helpers.rb
80
82
  - social_linker.gemspec
81
83
  homepage: https://murb.nl/blog?tags=social_linker
82
84
  licenses:
@@ -1,9 +0,0 @@
1
- module SocialLinker
2
- class Railtie < Rails::Railtie
3
- ActiveSupport.on_load(:action_view) do
4
- puts "Action view loaded, including SocialLinker::ViewHelpers"
5
- require 'social_linker/view_helpers'
6
- include SocialLinker::ViewHelpers
7
- end
8
- end
9
- end
@@ -1,65 +0,0 @@
1
- module SocialLinker
2
- module ViewHelpers
3
- # renders a metatag
4
- # param [String, Symbol] name (or property) (defaults to name, values starting with 'og:' (opengraph) will be using the property attribute)
5
- # param [String, Symbol] content (the value for the name or the property)
6
- # @returns [String, nil] nil is returned when the content is empty
7
- def meta_tag(name, content)
8
- name_or_property_section = name.start_with?("og:") ? "property=\"#{erb_sanitized(name)}\"" : "name=\"#{erb_sanitized(name)}\""
9
- "<meta #{name_or_property_section} content=\"#{erb_sanitized(content)}\" />" if content and content != ""
10
- end
11
-
12
- def erb_sanitized(value)
13
- if defined? Rails
14
- h(value)
15
- else
16
- ERB::Util.h(value)
17
- end
18
- end
19
-
20
- # header_meta_tags renders the most important metatags based on the SocialLinker::Subject
21
- # param [SocialLinker::Subject] the SocialLinker::Subject initialized as complete as possible
22
- # param [Hash] options with site-defaults for `:site_title_postfix`, (e.g. article title - {site title postfix here}), `:domain` (the main url), `
23
- def header_meta_tags subject, options={}
24
- site_title_postfix = options[:site_title_postfix]
25
- header_html = []
26
- if subject
27
- domain = options[:domain] || subject.options[:domain]
28
-
29
- header_html << meta_tag("twitter:card", subject.media ? :summary_large_image : :summary)
30
- header_html << meta_tag("twitter:site", subject.options[:twitter_username])
31
- header_html << meta_tag("twitter:creator", subject.options[:twitter_username])
32
- header_html << meta_tag("twitter:domain", domain)
33
-
34
- if subject.url
35
- header_html << meta_tag("og:url", subject.canonical_url)
36
- header_html << "<link rel=\"canonical\" content=\"#{erb_sanitized(subject.canonical_url)}\" />"
37
- end
38
-
39
- header_html << meta_tag("keywords", subject.tags.join(" "))
40
- header_html << meta_tag("description", subject.summary)
41
-
42
- header_html << meta_tag("twitter:description", subject.summary)
43
- header_html << meta_tag("og:description", subject.summary)
44
-
45
- if subject.media
46
- header_html << meta_tag("twitter:image:src", subject.media)
47
- header_html << meta_tag("og:image", subject.media)
48
- header_html << meta_tag("og:image:type", subject.options[:image_type])
49
- end
50
- end
51
-
52
- title = @title
53
- title = subject.title if subject
54
- site_title = [title, site_title_postfix].uniq.compact.join(" - ")
55
- header_html << "<title>#{site_title}</title>"
56
- header_html << meta_tag("twitter:title", title)
57
- header_html << meta_tag("og:title", title)
58
-
59
- header_html.compact!
60
- header_html.join("\n") if header_html
61
-
62
- end
63
-
64
- end
65
- end