cortex-snippets-client 1.0.4 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +159 -1
- data/lib/cortex/snippets/version.rb +1 -1
- data/lib/cortex/snippets/webpage.rb +8 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b1b29afae0364c3a870b8299cf725fb533a1b04
|
4
|
+
data.tar.gz: 0a9e78580faabedf599c52b50a94397a616a584a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c42611122362e4f16ba77a51e6b093593a308dca3d2c94b61aaa1c9950566f5b6260ecb0cf4de7538c94017e73e51a93da1851dc1a3422b7c3797c04bc9d2f25
|
7
|
+
data.tar.gz: 1347c202d705e37af9ba5a7f4b96a5501155cf873eb5e10d42c168fbfa8e7c20821215126a83347953a74c663b06a22145948788a42b048155a3c39b955fc7f2
|
data/README.md
CHANGED
@@ -1 +1,159 @@
|
|
1
|
-
#
|
1
|
+
# Cortex Snippets Client
|
2
|
+
|
3
|
+
This is the Ruby Client of the Snippets Library for [Cortex](https://github.com/cortex-cms). The purpose of this gem is to create a simplified way of accessing the content of snippets that are modifiable in the Cortex IPE and rendering them as useable markup, as well as the various other attributes of Webpages.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
|
8
|
+
To Install simply run
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem install cortex-snippets-client
|
12
|
+
```
|
13
|
+
|
14
|
+
Or if you're installing from a Gemfile include it as
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
gem 'cortex-snippets-client`, '~> 1.0.4'
|
18
|
+
```
|
19
|
+
|
20
|
+
And then run
|
21
|
+
|
22
|
+
```ruby
|
23
|
+
bundle install
|
24
|
+
```
|
25
|
+
|
26
|
+
## Setup
|
27
|
+
|
28
|
+
|
29
|
+
In order to get started using the Cortex Snippets Client you're going to need to initialize a [Cortex Client](https://github.com/cortex-cms/cortex-client-ruby) object that you will be using to interact with Cortex. You will need a separate client for each tenant you have active.
|
30
|
+
|
31
|
+
The following is a basic setup for a Cortex Client:
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
$cortex = Cortex::Client.new(
|
35
|
+
key: 1234567,
|
36
|
+
secret: ABCDEFG,
|
37
|
+
base_url: http://localhost:3000,
|
38
|
+
scopes: view:webpages)
|
39
|
+
```
|
40
|
+
|
41
|
+
Once you have your Cortex Client object you can simply initialize and store a Cortex Snippet Client object by creating it like so:
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
@cortex_snippet_client = Cortex::Snippets::Client.new($cortex)
|
45
|
+
```
|
46
|
+
|
47
|
+
## Usage
|
48
|
+
|
49
|
+
|
50
|
+
Use of this gem is generally split into two categories: Snippets and Webpages
|
51
|
+
|
52
|
+
**Snippets** refers to blocks of markup that are editable in Cortex IPE and, through the use of this gem, persist into the tenant application. This allows the copy changes made in IPE to replace default blocks on the page and your changes to be shown.
|
53
|
+
|
54
|
+
**Webpages** refer to the created webpages themselves, which have several bits of relevant metadata including, but not limited to: title, keywords, and indexing information.
|
55
|
+
|
56
|
+
### Snippets
|
57
|
+
|
58
|
+
|
59
|
+
**Basic Usage**
|
60
|
+
|
61
|
+
To be properly used, snippets must have both a reference in the Markup:
|
62
|
+
|
63
|
+
```haml
|
64
|
+
# A view in your application
|
65
|
+
|
66
|
+
= snippet :id => 'a_snippet_name' do
|
67
|
+
%h1.heavy
|
68
|
+
This is my awesome title
|
69
|
+
```
|
70
|
+
|
71
|
+
And a call to the Snippets Client:
|
72
|
+
|
73
|
+
```ruby
|
74
|
+
# app/helpers/application_helper.rb
|
75
|
+
|
76
|
+
def snippet(options = {}, &block)
|
77
|
+
@cortex_snippet_client.snippet(request, options, capture(&block))
|
78
|
+
end
|
79
|
+
```
|
80
|
+
|
81
|
+
This will take the given id of the snippet, search the relevant Cortex Tenant for any matches, and return a block of content - if it does not find a match it will simply return the default block of Markup.
|
82
|
+
|
83
|
+
**Additional Usage**
|
84
|
+
|
85
|
+
Any additional metadata you pass into the `options` hash will extend to the final, rendered snippet. For example:
|
86
|
+
|
87
|
+
```haml
|
88
|
+
# A view in your application
|
89
|
+
|
90
|
+
= snippet :id => 'a_snippet_name', :class => 'some_test_class' do
|
91
|
+
%h1.heavy
|
92
|
+
This is my awesome title
|
93
|
+
```
|
94
|
+
|
95
|
+
Will result in the following markup being rendered:
|
96
|
+
|
97
|
+
```html
|
98
|
+
<snippet id="a_snippet_name" class="some_test_class">
|
99
|
+
<h1 class="heavy">
|
100
|
+
This is my awesome title
|
101
|
+
</h1>
|
102
|
+
</snippet>
|
103
|
+
```
|
104
|
+
|
105
|
+
### Webpages
|
106
|
+
|
107
|
+
The webpage system of this gem is used quite differently, in order to properly reference it you will need to do the following:
|
108
|
+
|
109
|
+
```ruby
|
110
|
+
webpage = @cortex_snippet_client.current_webpage(request)
|
111
|
+
```
|
112
|
+
|
113
|
+
This will give you a webpage object from your current Cortex Tenant with all of the given metadata for that page as attributes. Here is a comprehensive list of accessible information for any Webpage:
|
114
|
+
|
115
|
+
|Attribute|Description|
|
116
|
+
|---|---|
|
117
|
+
|seo_title| The title for the current Webpage.|
|
118
|
+
|seo_description| The description of the current Webpage.|
|
119
|
+
|seo_keywords| An array of search keywords for the current Webpage.<sup>1</sup>|
|
120
|
+
|seo_robots| An array of indexing robot information for the current Webpage.<sup>2</sup>|
|
121
|
+
|noindex| The noindex information for the Webpage. Included in `seo_robots`|
|
122
|
+
|nofollow| The nofollow information for the Webpage. Included in `seo_robots`|
|
123
|
+
|noodp| The noodp information for the Webpage. Included in `seo_robots`|
|
124
|
+
|nosnippet| The nosnippet information for the Webpage. Included in `seo_robots`|
|
125
|
+
|noarchive| The noarchive information for the Webpage. Included in `seo_robots`|
|
126
|
+
|noimageindex| The noimageindex information for the Webpage. Included in `seo_robots`|
|
127
|
+
|dynamic_yield| A hash of Dynamic Yield information from the current Webpage.|
|
128
|
+
|snippets|An array of the associated snippets with the current Webpage.|
|
129
|
+
|
130
|
+
|
131
|
+
1:<br>
|
132
|
+
The resulting array from `seo_keywords` can be entered into a single keyword meta tag like so:
|
133
|
+
|
134
|
+
```haml
|
135
|
+
%meta{name: 'keywords', content: webpage.seo_keywords.join(',') }
|
136
|
+
```
|
137
|
+
|
138
|
+
2:<br>
|
139
|
+
The resulting array from `seo_robots` can be entered into a single robots meta tag like so:
|
140
|
+
|
141
|
+
```haml
|
142
|
+
%meta{name: 'robots', content: webpage.seo_robots.join(',') }
|
143
|
+
```
|
144
|
+
|
145
|
+
## Changelog
|
146
|
+
See [CHANGELOG.md](CHANGELOG.md) for a comprehensive and updated history of changes to this gem. Additionally this gem uses GitHub version, so you can go there and see any general release notes.
|
147
|
+
|
148
|
+
## Contributing
|
149
|
+
The following is in addition to the usual GitHub flow (fork the repo, pull it down locally, etc...)
|
150
|
+
|
151
|
+
* If you would like to contribute to this gem please create a branch entitled `issue/#{GitHub Issue Number}-#{Issue Name}`. If you are submitting a new feature without an attached issue then name your branch `feature/#{Descriptive Feature Name}`
|
152
|
+
* Make your changes locally and write tests for all created changes
|
153
|
+
* For any added commits please follow the patterns of [Semantic Git Commits](https://github.com/ElliottAYoung/git-semantic-commits)
|
154
|
+
* Create a Pull Request in which you detail what you changed, why you changed it, and every other relevant detail to your PR. If your PR is for an open issue please link to that.
|
155
|
+
* Correspond with us! (We're really very nice)
|
156
|
+
* When it's accepted and approved we will merge in your code!!
|
157
|
+
|
158
|
+
## License
|
159
|
+
Apache License, Version 2.0
|
@@ -59,6 +59,14 @@ module Cortex
|
|
59
59
|
}
|
60
60
|
end
|
61
61
|
|
62
|
+
def table_widget_data
|
63
|
+
JSON.parse(@webpage[:tables_widget_json] || 'null', quirks_mode: true)
|
64
|
+
end
|
65
|
+
|
66
|
+
def table_widget_data_for(table_name)
|
67
|
+
table_widget_data&.[](table_name) || []
|
68
|
+
end
|
69
|
+
|
62
70
|
def snippets
|
63
71
|
@webpage[:snippets]
|
64
72
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cortex-snippets-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- CareerBuilder Employer Site & Content Products
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-03-
|
11
|
+
date: 2017-03-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cortex-client
|