Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make column_count configurable #53

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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