Skip to content

Commit

Permalink
Cleaned up some field samples in the macros
Browse files Browse the repository at this point in the history
Fixes #54
Bump version to 2.0.2
  • Loading branch information
erikreagan committed Aug 5, 2018
1 parent 4f5fc6f commit e9778a7
Show file tree
Hide file tree
Showing 18 changed files with 178 additions and 33 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

## 2.0.2 - 2018-08-05

### Changed

- Made a few additional corrections and improvements to code samples

### Fixed

- Fixed a bug some plugins confliced with a macro loader in twig ([#54](https://github.com/focuslabllc/craft-cheat-sheet/issues/54))

## 2.0.1 - 2018-08-04

### Changed
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "focuslabllc/craft-cheat-sheet",
"description": "A fast and customized set of instantly usable Field code samples.",
"version": "2.0.1",
"version": "2.0.2",
"type": "craft-plugin",
"keywords": [
"craftcms",
Expand Down Expand Up @@ -37,7 +37,7 @@
"extra": {
"name": "Craft Cheat Sheet",
"handle": "cheat-sheet",
"version": "2.0.1",
"version": "2.0.2",
"documentationUrl": "https://github.com/focuslabllc/craft-cheat-sheet/blob/master/readme.md"
}
}
2 changes: 1 addition & 1 deletion src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* @copyright Copyright (c) 2016, Focus Lab, LLC
* @see https://github.com/focuslabllc/craft-cheat-sheet
* @package cheatsheet
* @version 2.0.0
* @version 2.0.2
*
* @property Settings $settings
* @property Fields $fields
Expand Down
2 changes: 1 addition & 1 deletion src/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @copyright Copyright (c) 2016, Focus Lab, LLC
* @see https://github.com/focuslabllc/craft-cheat-sheet
* @package cheatsheet
* @version 2.0.0
* @version 2.0.2
*/
class Settings extends Model
{
Expand Down
2 changes: 1 addition & 1 deletion src/assets/CheatSheetAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @copyright Copyright (c) 2016, Focus Lab, LLC
* @see https://github.com/focuslabllc/craft-cheat-sheet
* @package cheatsheet
* @version 2.0.0
* @version 2.0.2
*/
class CheatSheetAsset extends AssetBundle
{
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/RoutesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* @copyright Copyright (c) 2016, Focus Lab, LLC
* @see https://github.com/focuslabllc/craft-cheat-sheet
* @package cheatsheet
* @version 2.0.0
* @version 2.0.2
*/
class RoutesController extends Controller
{
Expand Down
25 changes: 13 additions & 12 deletions src/services/Fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* @copyright Copyright (c) 2016, Focus Lab, LLC
* @see https://github.com/focuslabllc/craft-cheat-sheet
* @package cheatsheet
* @version 2.0.0
* @version 2.0.2
*/
class Fields extends BaseObject
{
Expand Down Expand Up @@ -62,19 +62,19 @@ private function dataPrep(): array
$whitespace = str_replace('\t', ' ', $whitespace);

return [
'pageTitle' => 'Field Cheat Sheet',
'version' => $plugin->version,
'whitespace' => $whitespace,
'groups' => $fieldsService->getAllGroups(),
'fields' => $fieldsService->getAllFields(),
'pageTitle' => 'Field Cheat Sheet',
'version' => $plugin->version,
'whitespace' => $whitespace,
'groups' => $fieldsService->getAllGroups(),
'fields' => $fieldsService->getAllFields(),
'currentContext' => $currentContext,
'tagContexts' => [
'asset' => ['title' => 'Assets', 'tag' => 'asset'],
'cat' => ['title' => 'Categories', 'tag' => 'category'],
'entry' => ['title' => 'Entries', 'tag' => 'entry'],
'tagContexts' => [
'asset' => ['title' => 'Assets', 'tag' => 'asset'],
'cat' => ['title' => 'Categories', 'tag' => 'category'],
'entry' => ['title' => 'Entries', 'tag' => 'entry'],
'global' => ['title' => 'Globals', 'tag' => 'globalSet'],
'tag' => ['title' => 'Tags', 'tag' => 'tag'],
'user' => ['title' => 'Users', 'tag' => 'user']
'tag' => ['title' => 'Tags', 'tag' => 'tag'],
'user' => ['title' => 'Users', 'tag' => 'user']
],
'nativeFieldTypes' => [
Assets::class,
Expand Down Expand Up @@ -104,6 +104,7 @@ private function dataPrep(): array
Color::class => 'cs_Color',
Date::class => 'cs_Date',
Dropdown::class => 'cs_Dropdown',
Email::class => 'cs_Email',
Entries::class => 'cs_Entries',
Lightswitch::class => 'cs_Lightswitch',
Matrix::class => 'cs_Matrix',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
--------------------------------------------- #}
{%- macro codeBlock(title, code, helpText) %}
<div class="code_block">
<h3>{{ title }}</h3>
<h3>{{ title|raw}}</h3>
{% if helpText %}
<div class="description">
<p>{{ helpText|md }}</p>
Expand Down
51 changes: 48 additions & 3 deletions src/templates/frontEnd/_includes/_coreMacros/fields.twig
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@
~ '{% if myCategory %}\n'
~ data.whitespace ~ '...\n'
~ '{% endif %}'
, 'This is mostly used in a scenario where you only expect one category to be selected. The result is still a "set" of categories so we just grab the "first" one.')}}
, 'This is mostly used in a scenario where you only expect one category to be selected. The result is still a "set" of categories so we just grab the first one.')}}

{% endmacro -%}

Expand All @@ -168,7 +168,7 @@
)}}


{{ macros.codeBlock('Loop through the *selected* options', '
{{ macros.codeBlock('Loop through the <em>selected</em> options', '
<ul>\n'
~ data.whitespace ~ '{% for option in '
~ data.sampleTag
Expand Down Expand Up @@ -216,6 +216,25 @@
{% if ' ~ data.sampleTag ~ ' %} ... {% endif %}'
)}}

{{ macros.codeBlock('Adding to page style rules', '
{% if '
~ data.sampleTag
~ ' %}\n'
~ data.whitespace
~ '<style type="text/css">\n'
~ data.whitespace ~ data.whitespace
~ '.content a {\n'
~ data.whitespace ~ data.whitespace ~ data.whitespace
~ 'color: {{ '
~ data.sampleTag
~ '.getHex() }};\n'
~ data.whitespace ~ data.whitespace
~ '}\n'
~ data.whitespace
~ '</style>\n'
~ '{% endif %}'
)}}

{{ macros.codeBlock('As rgb() syntax', '
{{ ' ~ data.sampleTag ~ '.rgb }}'
)}}
Expand Down Expand Up @@ -270,6 +289,19 @@

{% endmacro -%}

{%- macro cs_Email(data) %}
{% import _self as macros %}

{{ macros.codeBlock('Field name', '
{{ ' ~ data.sampleTag ~ ' }}'
)}}

{{ macros.codeBlock('"If exists" conditional', '
{% if ' ~ data.sampleTag ~ ' %} ... {% endif %}'
)}}

{% endmacro -%}

{%- macro cs_Entries(data) %}
{% import _self as macros %}

Expand Down Expand Up @@ -565,6 +597,19 @@

{% endmacro -%}

{%- macro cs_Redactor(data) %}
{% import _self as macros %}

{{ macros.codeBlock('Field name', '
{{ ' ~ data.sampleTag ~ ' }}'
)}}

{{ macros.codeBlock('"If exists" conditional', '
{% if ' ~ data.sampleTag ~ ' %} ... {% endif %}'
)}}

{% endmacro -%}

{%- macro cs_RichText(data) %}
{% import _self as macros %}

Expand Down Expand Up @@ -730,7 +775,7 @@
)}}


{{ macros.codeBlock('Avoid a loop if your field limits to 1 user', '
{{ macros.codeBlock('Avoid a loop if your field limits to 1 tag', '
{% if '
~ data.sampleTag
~ '.one() %}\n'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@
~ '{% if myCategory %}\n'
~ data.whitespace ~ '...\n'
~ '{% endif %}'
, 'This is mostly used in a scenario where you only expect one category to be selected. The result is still a "set" of categories so we just grab the "first" one.')}}
, 'This is mostly used in a scenario where you only expect one category to be selected. The result is still a "set" of categories so we just grab the first one.')}}

{% endmacro -%}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
)}}


{{ macros.codeBlock('Loop through the *selected* options', '
{{ macros.codeBlock('Loop through the <em>selected</em> options', '
<ul>\n'
~ data.whitespace ~ '{% for option in '
~ data.sampleTag
Expand Down
19 changes: 19 additions & 0 deletions src/templates/frontEnd/_includes/_fieldMacros/Color.twig
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,25 @@
{% if ' ~ data.sampleTag ~ ' %} ... {% endif %}'
)}}

{{ macros.codeBlock('Adding to page style rules', '
{% if '
~ data.sampleTag
~ ' %}\n'
~ data.whitespace
~ '<style type="text/css">\n'
~ data.whitespace ~ data.whitespace
~ '.content a {\n'
~ data.whitespace ~ data.whitespace ~ data.whitespace
~ 'color: {{ '
~ data.sampleTag
~ '.getHex() }};\n'
~ data.whitespace ~ data.whitespace
~ '}\n'
~ data.whitespace
~ '</style>\n'
~ '{% endif %}'
)}}

{{ macros.codeBlock('As rgb() syntax', '
{{ ' ~ data.sampleTag ~ '.rgb }}'
)}}
Expand Down
12 changes: 12 additions & 0 deletions src/templates/frontEnd/_includes/_fieldMacros/Email.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{%- macro cs_Email(data) %}
{% import _self as macros %}

{{ macros.codeBlock('Field name', '
{{ ' ~ data.sampleTag ~ ' }}'
)}}

{{ macros.codeBlock('"If exists" conditional', '
{% if ' ~ data.sampleTag ~ ' %} ... {% endif %}'
)}}

{% endmacro -%}
12 changes: 12 additions & 0 deletions src/templates/frontEnd/_includes/_fieldMacros/Redactor.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{%- macro cs_Redactor(data) %}
{% import _self as macros %}

{{ macros.codeBlock('Field name', '
{{ ' ~ data.sampleTag ~ ' }}'
)}}

{{ macros.codeBlock('"If exists" conditional', '
{% if ' ~ data.sampleTag ~ ' %} ... {% endif %}'
)}}

{% endmacro -%}
2 changes: 1 addition & 1 deletion src/templates/frontEnd/_includes/_fieldMacros/Tags.twig
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
)}}


{{ macros.codeBlock('Avoid a loop if your field limits to 1 user', '
{{ macros.codeBlock('Avoid a loop if your field limits to 1 tag', '
{% if '
~ data.sampleTag
~ '.one() %}\n'
Expand Down
8 changes: 5 additions & 3 deletions src/templates/frontEnd/_includes/_fieldMacros/_template.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@
<p>You can setup extra info below your snippets.</p>
</div>

{{ macros.codeBlock('Field name', '
{{ macros.codeBlock(
'Field name', '
{{ ' ~ data.sampleTag ~ ' }}'
), 'This is an example of code-block specific additional text if you need to prefix the sample code with anything.'}}
'This is an example of code-block specific additional text if you need to prefix the sample code with anything.'
) }}


{{ macros.codeBlock('"If exists" conditional', '
{% if ' ~ data.sampleTag ~ '|length %} ... {% endif %}'
)}}
) }}

<div class="extra">
<p>Or you can setup extra info below your snippets.</p>
Expand Down

0 comments on commit e9778a7

Please sign in to comment.