Skip to content

Commit

Permalink
Make column_count configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
dv authored and marcandre committed Jan 2, 2018
1 parent 1b32be3 commit 1534991
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 3 deletions.
23 changes: 23 additions & 0 deletions README.md
Expand Up @@ -108,6 +108,29 @@ welcome.html.haml => welcome.html.inky-haml
pw_reset.html.erb => pw_reset.html.inky-erb
```

## Other options

### Column Count

You can change the column count in the initializer too:

```ruby
# config/initializers/inky.rb
Inky.configure do |config|
config.column_count = 24
end
```

Make sure to change the SASS variable as well:

```sass
# assets/stylesheets/foundation_emails.scss
# ...
$grid-column-count: 24;
@import "foundation-emails";
```

## Custom Elements

Inky simplifies the process of creating HTML emails by expanding out simple tags like `<row>` and `<column>` into full table syntax. The names of the tags can be changed with the `components` setting.
Expand Down
2 changes: 1 addition & 1 deletion lib/inky.rb
Expand Up @@ -25,7 +25,7 @@ def initialize(options = {})

self.component_lookup = components.invert

self.column_count = options[:column_count] || 12
self.column_count = options[:column_count] || ::Inky.configuration.column_count

self.component_tags = components.values
end
Expand Down
4 changes: 3 additions & 1 deletion lib/inky/configuration.rb
Expand Up @@ -15,17 +15,19 @@ def self.configuration=(config)
# ```
# Inky.configure do |config|
# config.template_engine = :slim
# config.column_count = 24
# end
# ```
def self.configure
yield configuration
end

class Configuration
attr_accessor :template_engine
attr_accessor :template_engine, :column_count

def initialize
@template_engine = :erb
@column_count = 12
end
end
end
1 change: 1 addition & 0 deletions lib/inky/rails/template_handler.rb
Expand Up @@ -14,6 +14,7 @@ def engine_handler

def call(template)
compiled_source = engine_handler.call(template)

"Inky::Core.new.release_the_kraken(begin; #{compiled_source};end)"
end

Expand Down
8 changes: 7 additions & 1 deletion spec/configuration_spec.rb
Expand Up @@ -14,11 +14,17 @@
end

describe "#configuration=" do
it "can set value" do
it "can set template_engine" do
config = Inky::Configuration.new
config.template_engine = :haml
expect(config.template_engine).to eq(:haml)
end

it "can set column_count" do
config = Inky::Configuration.new
config.column_count = 4
expect(config.column_count).to eq(4)
end
end

describe "#configuration=" do
Expand Down
44 changes: 44 additions & 0 deletions spec/grid_spec.rb
Expand Up @@ -57,6 +57,50 @@
compare(input, expected)
end

it 'creates a single column with default large and small classes' do
input = '<columns>One</columns>'
expected = <<-HTML
<th class="small-12 large-12 columns first last">
<table>
<tr>
<th>One</th>
<th class="expander"></th>
</tr>
</table>
</th>
HTML

compare(input, expected)
end

it 'creates a single column with default large and small classes using the column_count option' do
begin
@previous_column_count = Inky.configuration.column_count

Inky.configure do |config|
config.column_count = 5
end

input = '<columns>One</columns>'
expected = <<-HTML
<th class="small-5 large-5 columns first last">
<table>
<tr>
<th>One</th>
<th class="expander"></th>
</tr>
</table>
</th>
HTML

compare(input, expected)
ensure
Inky.configure do |config|
config.column_count = @previous_column_count
end
end
end

it 'creates a single column with first and last classes' do
input = '<columns large="12" small="12">One</columns>'
expected = <<-HTML
Expand Down

0 comments on commit 1534991

Please sign in to comment.