Skip to content

Instantly share code, notes, and snippets.

@johanobergman
Last active September 29, 2015 22:37
Show Gist options
  • Select an option

  • Save johanobergman/60483a8f49c30f245eef to your computer and use it in GitHub Desktop.

Select an option

Save johanobergman/60483a8f49c30f245eef to your computer and use it in GitHub Desktop.

Revisions

  1. johanobergman revised this gist Oct 11, 2014. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions 4. section-helpers.js
    Original file line number Diff line number Diff line change
    @@ -7,8 +7,8 @@ section = function(name, options) {

    yieldSection = function(name, options) {
    var context, section;
    if ((context = this.get('parent')) && (section = context.get(name + "Section"))) {
    section(context);
    if ((context = this.get('parent')) && (sectionBlock = context.get(name + "Section"))) {
    sectionBlock(context);
    }
    };

  2. johanobergman revised this gist Oct 11, 2014. 5 changed files with 0 additions and 0 deletions.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
    File renamed without changes.
  3. johanobergman renamed this gist Oct 11, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. johanobergman revised this gist Oct 11, 2014. 3 changed files with 1 addition and 1 deletion.
    File renamed without changes.
    2 changes: 1 addition & 1 deletion my-component.hbs
    Original file line number Diff line number Diff line change
    @@ -13,5 +13,5 @@
    {{else}}
    <p>Just some generic content in case nothing else was specified.</p>
    {{/if}}
    </div>
    File renamed without changes.
  5. johanobergman revised this gist Oct 11, 2014. 3 changed files with 20 additions and 1 deletion.
    4 changes: 4 additions & 0 deletions app.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    import { section, yieldSection } from 'app-name/helpers/section-helpers';

    Ember.Handlebars.registerHelper('section', section);
    Ember.Handlebars.registerHelper('yield-section', yieldSection);
    2 changes: 1 addition & 1 deletion description.txt
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,3 @@
    Simply register the two helpers "section" and "yield-section", and start right away!

    See example below:
    See example below, using ember-cli:
    15 changes: 15 additions & 0 deletions section-helpers.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    import Ember from 'ember';
    var section, yieldSection;

    section = function(name, options) {
    this.set(name + "Section", options.fn);
    };

    yieldSection = function(name, options) {
    var context, section;
    if ((context = this.get('parent')) && (section = context.get(name + "Section"))) {
    section(context);
    }
    };

    export { section, yieldSection };
  6. johanobergman revised this gist Oct 11, 2014. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions my-component.hbs
    Original file line number Diff line number Diff line change
    @@ -8,8 +8,8 @@

    {{#if parent.footerSection}}
    <div class="component-footer">
    {{yield-section 'footer'}}
    </div>
    {{yield-section 'footer'}}
    </div>
    {{else}}
    <p>Just some generic content in case nothing else was specified.</p>
    {{/if}}
  7. johanobergman revised this gist Oct 11, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion my-component.hbs
    Original file line number Diff line number Diff line change
    @@ -11,7 +11,7 @@
    {{yield-section 'footer'}}
    </div>
    {{else}}
    <p>Just some generic content in case nothing else was specified.</p>
    <p>Just some generic content in case nothing else was specified.</p>
    {{/if}}

    </div>
  8. johanobergman revised this gist Oct 11, 2014. 1 changed file with 7 additions and 7 deletions.
    14 changes: 7 additions & 7 deletions my-component.hbs
    Original file line number Diff line number Diff line change
    @@ -6,12 +6,12 @@

    {{yield}}

    {{#if parent.footerSection}}
    <div class="component-footer">
    {{yield-section 'footer'}}
    </div>
    {{else}}
    <p>Just some generic content in case nothing else was specified.</p>
    {{/if}}
    {{#if parent.footerSection}}
    <div class="component-footer">
    {{yield-section 'footer'}}
    </div>
    {{else}}
    <p>Just some generic content in case nothing else was specified.</p>
    {{/if}}

    </div>
  9. johanobergman renamed this gist Oct 11, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  10. johanobergman revised this gist Oct 11, 2014. 3 changed files with 20 additions and 3 deletions.
    3 changes: 3 additions & 0 deletions description.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    Simply register the two helpers "section" and "yield-section", and start right away!

    See example below:
    4 changes: 2 additions & 2 deletions index.hbs
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    <h1>Hello from the index page!</h1>

    {{#my-component parent=controller}}
    {{#my-component parent=this}}

    {{#section 'header'}}
    <h2>Header inside my awesome component.</h2>
    @@ -12,7 +12,7 @@
    <p>

    {{#section 'footer'}}
    <p>Copyright FooCompany
    <p>Show me in the footer, please.<p>
    {{/section}}

    {{/my-component}}
    16 changes: 15 additions & 1 deletion my-component.hbs
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,17 @@
    <div class="my-component">


    <div class="component-header">
    {{yield-section 'header'}}
    </div>

    {{yield}}

    {{#if parent.footerSection}}
    <div class="component-footer">
    {{yield-section 'footer'}}
    </div>
    {{else}}
    <p>Just some generic content in case nothing else was specified.</p>
    {{/if}}

    </div>
  11. johanobergman revised this gist Oct 11, 2014. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions my-component.hbs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    <div class="my-component">

    </div>
  12. johanobergman created this gist Oct 11, 2014.
    18 changes: 18 additions & 0 deletions index.hbs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    <h1>Hello from the index page!</h1>

    {{#my-component parent=controller}}

    {{#section 'header'}}
    <h2>Header inside my awesome component.</h2>
    {{/section}}

    <p>
    Here goes the main body that fits into the standard "yield" helper.
    That's because I'm not in a section.
    <p>

    {{#section 'footer'}}
    <p>Copyright FooCompany
    {{/section}}

    {{/my-component}}