Skip to content

Commit

Permalink
Merge pull request #48 from jonduarte/improve-generator
Browse files Browse the repository at this point in the history
Improve block generator
  • Loading branch information
Andrew Walker committed Sep 2, 2015
2 parents cd771a3 + 64dcab3 commit 441dd2b
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 21 deletions.
25 changes: 15 additions & 10 deletions lib/generators/sir_trevor_rails/block/block_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,28 @@ def self.source_root
def create_block

# Copy the JS
copy_file "_block.js", "app/assets/javascripts/sir_trevor/blocks/#{name}.js"

gsub_file "app/assets/javascripts/sir_trevor/blocks/#{name}.js", /SirTrevor\.Blocks\.Example/, "SirTrevor.Blocks.#{name.capitalize}"
gsub_file "app/assets/javascripts/sir_trevor/blocks/#{name}.js", /return "Example"/, "return '#{name.capitalize}'"
gsub_file "app/assets/javascripts/sir_trevor/blocks/#{name}.js", /type: 'example'/, "type: '#{name.downcase}'"
template "_block.js.erb", "app/assets/javascripts/sir_trevor/blocks/#{file_name}.js"

# Copy the HTML
copy_file "_block.html.erb", "app/views/sir_trevor/blocks/_#{name}_block.html.erb"
gsub_file "app/views/sir_trevor/blocks/_#{name}_block.html.erb", /\s(-block)/, " #{name}-block"
gsub_file "app/views/sir_trevor/blocks/_#{name}_block.html.erb", /\s(_block)/, " #{name}_block"
template "_block.html.erb", "app/views/sir_trevor/blocks/_#{file_name}_block.html.erb"

# Copy the BlockDecorator
copy_file "_block.rb", "app/sir_trevor_blocks/#{name}_block.rb"
gsub_file "app/sir_trevor_blocks/#{name}_block.rb", /ExampleBlock/, " #{name}Block"
template "_block.rb.erb", "app/sir_trevor_blocks/#{file_name}_block.rb"
end

private

def file_name
name.underscore
end

def block_name
file_name.camelize
end

def css_class
file_name.dasherize
end
end
end
end
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<div class="content-block example-block">
<%= example_block %>
</div>
<div class="content-block <%= css_class %>-block">
<%%= <%= file_name %>_block %>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,18 @@
Author: C J Bell @ madebymany
*/

SirTrevor.Blocks.Example = (function(){

SirTrevor.Blocks.<%= block_name %> = (function(){
return SirTrevor.Block.extend({

// String; Names the block
// Note – please use underscores when naming
// Eg example_block should be ExampleBlock
type: 'example',
type: '<%= file_name %>',

// Function; the title displayed in the toolbar
// Can return a translated string (if required)
title: function() {
// return i18n.t('blocks:example:title');
return "Example";
return "<%= block_name %>";
},

// Boolean; show this blockType of the toolbar
Expand Down Expand Up @@ -200,4 +198,4 @@ SirTrevor.Blocks.Example = (function(){
}
});

})();
})();
2 changes: 0 additions & 2 deletions lib/generators/sir_trevor_rails/block/templates/_block.rb

This file was deleted.

2 changes: 2 additions & 0 deletions lib/generators/sir_trevor_rails/block/templates/_block.rb.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class <%= block_name %>Block < SirTrevorRails::Block
end

0 comments on commit 441dd2b

Please sign in to comment.