Skip to content

Commit

Permalink
Merge pull request #9 from SwedbankPay/feature/support_different_types
Browse files Browse the repository at this point in the history
Add support for class name
  • Loading branch information
NullableInt authored May 28, 2020
2 parents 3d18497 + 7cf35e2 commit a55a0e7
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 112 deletions.
198 changes: 96 additions & 102 deletions .github/workflows/gempush.yml
Original file line number Diff line number Diff line change
@@ -1,111 +1,105 @@
name: Ruby Gem

on:
push:
branches: [ master ]
tags:
- '*'
pull_request:
branches: [ master ]
on: [pull_request, push]

jobs:
build:
name: Build, Test and Publish Ruby Gem
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Fetch all history for all tags and branches
run: |
git fetch --prune --unshallow --tags
echo "REF: ${{ github.ref }}"
- name: Install GitVersion
uses: gittools/actions/gitversion/[email protected]
with:
versionSpec: '5.2.x'

- name: Execute GitVersion
id: gitversion
uses: gittools/actions/gitversion/[email protected]

- name: Version variables for unstable builds
id: unstable
if: startsWith(github.ref, 'refs/tags/') != true
env:
LABEL: ${{ steps.gitversion.outputs.preReleaseTagWithDash }}.${{ steps.gitversion.outputs.commitsSinceVersionSourcePadded }}
run: |
echo "Pre-release: ${LABEL}"
echo "::set-output name=label::${LABEL}"
- name: Create gem version number
id: gemversion
env:
GEM_VERSION: "${{ steps.gitversion.outputs.majorMinorPatch }}${{ steps.unstable.outputs.label }}"
run: |
echo "Gem version: ${GEM_VERSION}"
echo "::set-output name=version::${GEM_VERSION}"
- name: Set up Ruby 2.6
uses: actions/setup-ruby@v1
with:
ruby-version: 2.6.x

- name: Cache dependencies
uses: actions/cache@v1
with:
path: vendor/bundle
key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
restore-keys: ${{ runner.os }}-gems-

- name: Bundle install
run: |
gem install bundler
bundle config path vendor/bundle
bundle install --jobs 4 --retry 3
- name: Build gem
id: gem
env:
GEM_VERSION: ${{ steps.gemversion.outputs.version }}
run: |
GEM_BUILD_NAME=$(gem build jekyll-material-icon-tag.gemspec | awk '/File/ {print $2}')
echo "Gem filename: '${GEM_BUILD_NAME}'"
echo "::set-output name=name::${GEM_BUILD_NAME}"
- name: Test gem
run: |
bundle exec rake test
- name: Upload artifact
uses: actions/upload-artifact@v2-preview
with:
name: ${{ steps.gem.outputs.name }}
path: ${{ steps.gem.outputs.name }}

- name: Publish to GPR
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OWNER: SwedbankPay
run: |
mkdir -p $HOME/.gem
touch $HOME/.gem/credentials
chmod 0600 $HOME/.gem/credentials
printf -- "---\n:github: Bearer ${GITHUB_TOKEN}\n" > $HOME/.gem/credentials
set -e
gem push --KEY github \
--host https://rubygems.pkg.github.com/${OWNER} \
${{ steps.gem.outputs.name }} \
|| echo "push failed ($?) probably due to version '${{ steps.gemversion.outputs.version }}' already existing in GPR."
- name: Publish to RubyGems
if: startsWith(github.ref, 'refs/tags/') # Only publish tagged commits
env:
RUBYGEMS_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}
run: |
mkdir -p $HOME/.gem
touch $HOME/.gem/credentials
chmod 0600 $HOME/.gem/credentials
printf -- "---\n:rubygems_api_key: ${RUBYGEMS_API_KEY}\n" > $HOME/.gem/credentials
gem push ${{ steps.gem.outputs.name }}
- uses: actions/checkout@v2

- name: Fetch all history for all tags and branches
run: |
git fetch --prune --unshallow --tags
echo "REF: ${{ github.ref }}"
- name: Install GitVersion
uses: gittools/actions/gitversion/[email protected]
with:
versionSpec: "5.2.x"

- name: Execute GitVersion
id: gitversion
uses: gittools/actions/gitversion/[email protected]

- name: Version variables for unstable builds
id: unstable
if: startsWith(github.ref, 'refs/tags/') != true
env:
LABEL: ${{ steps.gitversion.outputs.preReleaseTagWithDash }}.${{ steps.gitversion.outputs.commitsSinceVersionSourcePadded }}
run: |
echo "Pre-release: ${LABEL}"
echo "::set-output name=label::${LABEL}"
- name: Create gem version number
id: gemversion
env:
GEM_VERSION: "${{ steps.gitversion.outputs.majorMinorPatch }}${{ steps.unstable.outputs.label }}"
run: |
echo "Gem version: ${GEM_VERSION}"
echo "::set-output name=version::${GEM_VERSION}"
- name: Set up Ruby 2.6
uses: actions/setup-ruby@v1
with:
ruby-version: 2.6.x

- name: Cache dependencies
uses: actions/cache@v1
with:
path: vendor/bundle
key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
restore-keys: ${{ runner.os }}-gems-

- name: Bundle install
run: |
gem install bundler
bundle config path vendor/bundle
bundle install --jobs 4 --retry 3
- name: Build gem
id: gem
env:
GEM_VERSION: ${{ steps.gemversion.outputs.version }}
run: |
GEM_BUILD_NAME=$(gem build jekyll-material-icon-tag.gemspec | awk '/File/ {print $2}')
echo "Gem filename: '${GEM_BUILD_NAME}'"
echo "::set-output name=name::${GEM_BUILD_NAME}"
- name: Test gem
run: |
bundle exec rake test
- name: Upload artifact
uses: actions/upload-artifact@v2-preview
with:
name: ${{ steps.gem.outputs.name }}
path: ${{ steps.gem.outputs.name }}

- name: Publish to GPR
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OWNER: SwedbankPay
run: |
mkdir -p $HOME/.gem
touch $HOME/.gem/credentials
chmod 0600 $HOME/.gem/credentials
printf -- "---\n:github: Bearer ${GITHUB_TOKEN}\n" > $HOME/.gem/credentials
set -e
gem push --KEY github \
--host https://rubygems.pkg.github.com/${OWNER} \
${{ steps.gem.outputs.name }} \
|| echo "push failed ($?) probably due to version '${{ steps.gemversion.outputs.version }}' already existing in GPR."
- name: Publish to RubyGems
if: startsWith(github.ref, 'refs/tags/') # Only publish tagged commits
env:
RUBYGEMS_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}
run: |
mkdir -p $HOME/.gem
touch $HOME/.gem/credentials
chmod 0600 $HOME/.gem/credentials
printf -- "---\n:rubygems_api_key: ${RUBYGEMS_API_KEY}\n" > $HOME/.gem/credentials
gem push ${{ steps.gem.outputs.name }}
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ gem 'jekyll-material-icon-tag'
```

And then execute:

```shell
$ bundle install
bundle install
```

Or install it yourself as:

```shell
$ gem install jekyll-material-icon-tag
gem install jekyll-material-icon-tag
```

## Usage
Expand All @@ -25,9 +28,17 @@ To render a Material Design Icon use as follows:
{% icon name_of_icon_you_want %}
```

You can also add style if you want a different material icon style:

```liquid
{% icon name_of_icon_you_want two-tone %}
{% icon another_icon_perhaps round %}
{% icon the_outlined_one outlined %}
```

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/jekyll-material-icon-tag. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/jekyll-material-icon-tag/blob/master/CODE_OF_CONDUCT.md).
Bug reports and pull requests are welcome on GitHub at <https://github.com/SwedbankPay/jekyll-material-icon-tag. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/SwedbankPay/jekyll-material-icon-tag/blob/master/CODE_OF_CONDUCT.md).

## License

Expand Down
21 changes: 15 additions & 6 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,23 @@ end

# Test generated output has valid HTML and links.
task :test => :build do
file = File.open("_site/index.html")
content = file.read
File.open("_site/index.html") do |file|
content = file.read

if content.include? "{% icon"
raise "Hell"
end
if content.include? "{% icon"
raise "Hell"
end

unless content.include? "material-icons-two-tone"
raise "Hell of two tones"
end

file.close
unless content.include? "material-icons-two-tone"
raise "Hell of two tones"
end

file.close
end
end

task :default => ["build"]
13 changes: 12 additions & 1 deletion lib/jekyll-material-icon-tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,18 @@ def initialize(tag_name, text, tokens)
end

def render(_)
"<i class=\"material-icons\">#{@text.strip}</i>"
iconname, type = parse_parameters @text

if type.nil?
"<i class=\"material-icons\">#{iconname.strip}</i>"
else
"<i class=\"material-icons-#{type.strip}\">#{iconname.strip}</i>"
end
end

def parse_parameters(text)
text.strip!
text.split(/\s+/)
end

Liquid::Template.register_tag "icon", self
Expand Down
2 changes: 2 additions & 0 deletions test/jekyll-material-icon-tag/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ layout: home
# About

This page test the {% icon check %} gem.
It also supports different {% icon alarm_on two-tone %} styles
{% icon aspect_ratio round %}.

0 comments on commit a55a0e7

Please sign in to comment.