Skip to content

Commit c638934

Browse files
committed
Merge branch 'develop'
2 parents 514b18f + 51cb35a commit c638934

File tree

3 files changed

+185
-2
lines changed

3 files changed

+185
-2
lines changed

README.md

Lines changed: 160 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,160 @@
1-
# cortex-snippets-client-ruby
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+
|tables_widget_data| A hash containing Tables Widget configuration data.|
129+
|tables_widget_data_for| An array (usually) containing table data for a single section.|
130+
|snippets|An array of the associated snippets with the current Webpage.|
131+
132+
1:<br>
133+
The resulting array from `seo_keywords` can be entered into a single keyword meta tag like so:
134+
135+
```haml
136+
%meta{name: 'keywords', content: webpage.seo_keywords.join(',') }
137+
```
138+
139+
2:<br>
140+
The resulting array from `seo_robots` can be entered into a single robots meta tag like so:
141+
142+
```haml
143+
%meta{name: 'robots', content: webpage.seo_robots.join(',') }
144+
```
145+
146+
## Changelog
147+
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.
148+
149+
## Contributing
150+
The following is in addition to the usual GitHub flow (fork the repo, pull it down locally, etc...)
151+
152+
* 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}`
153+
* Make your changes locally and write tests for all created changes
154+
* For any added commits please follow the patterns of [Semantic Git Commits](https://github.com/ElliottAYoung/git-semantic-commits)
155+
* 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.
156+
* Correspond with us! (We're really very nice)
157+
* When it's accepted and approved we will merge in your code!!
158+
159+
## License
160+
Apache License, Version 2.0

lib/cortex/snippets/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module Cortex
22
module Snippets
3-
VERSION = '1.0.4'
3+
VERSION = '1.1.2'
44
end
55
end

lib/cortex/snippets/webpage.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,30 @@ def dynamic_yield
5959
}
6060
end
6161

62+
def tables_widget_data
63+
JSON.parse(@webpage[:tables_widget_json] || 'null', quirks_mode: true)
64+
end
65+
66+
def tables_widget_data_for(section_name)
67+
tables_widget_data&.[](section_name) || []
68+
end
69+
70+
def accordion_group_widget_data
71+
JSON.parse(@webpage[:accordion_group_widget_json] || 'null', quirks_mode: true)
72+
end
73+
74+
def accordion_group_widget_data_for(section_name)
75+
accordion_group_widget_data&.[](section_name) || []
76+
end
77+
78+
def charts_widget_data
79+
JSON.parse(@webpage[:charts_widget_json] || 'null', quirks_mode: true)
80+
end
81+
82+
def charts_widget_data_for(section_name)
83+
charts_widget_data&.[](section_name) || {}
84+
end
85+
6286
def snippets
6387
@webpage[:snippets]
6488
end

0 commit comments

Comments
 (0)