Skip to content
This repository has been archived by the owner on Apr 20, 2018. It is now read-only.

Pass options.type to FileProcessor if present #524

Closed
wants to merge 1 commit into from

Conversation

mhupman
Copy link

@mhupman mhupman commented Mar 12, 2015

This should address some of the issues experienced in #255 when using configuration like the following:

usemin:
  "foo-html":
    files:
      src: ["src/www/index.html"]

    options:
      type: "html"

This change allows FileProcessor to process the file as html instead of foo-html, the latter of which won't get built-in pattern support.

@stephanebachelier
Copy link
Collaborator

@mhupman Need some tests.
Not sure about the name of the type option. It would be great to fallback on this option only if target name is not a known pattern.

@mhupman
Copy link
Author

mhupman commented Mar 14, 2015

type was an existing option, it just wasn't being passed to FileProcessor correctly. This change just allows the user to overrride the type (normally inferred by this.target) by specifying one.

@stephanebachelier
Copy link
Collaborator

@mhupman ok good catch!
It would be great to add some tests before being able to merge your work.

@stephanebachelier
Copy link
Collaborator

friendly ping @mhupman
Could you add a test ?

@mhupman
Copy link
Author

mhupman commented Mar 19, 2015

I don't mind taking a stab at, but honestly, I'm not sure where to start. Any pointers or thoughts about what you'd like to see in the test?

@stephanebachelier
Copy link
Collaborator

@mhupman could you add a test here. The idea of the test is to verify that your change make the code below to work as expected:

usemin:
  "foo-html":
    files:
      src: ["src/www/index.html"]

    options:
      type: "html"

@veraee
Copy link

veraee commented Apr 8, 2015

Just a try:

describe('usemin', function () {
  describe('multiTask', function () {
    beforeEach(directory('temp'));

    it('should honor options.type', function () {
      grunt.file.mkdir('build');
      grunt.file.mkdir('build/images');
      grunt.file.mkdir('build/images/misc');
      grunt.file.write('build/images/test.23012.png', 'foo');
      grunt.file.write('build/images/bar.23012.png', 'foo');
      grunt.file.write('build/images/misc/test.2a436.png', 'foo');
      grunt.file.copy(path.join(__dirname, 'fixtures/htmlprocessor_absolute.html'), 'build/index.html');

      grunt.log.muted = true;
      grunt.config.init();
      grunt.config('usemin', {
        foohtml: {
            files: {
                src: ["build/index.html"]
            },
            options: {
                type: "html"
            }
        }
      });
      grunt.task.run('usemin');
      grunt.task.start();

      var changed = grunt.file.read('build/index.html');

      assert.ok(changed.match(/<img src="\/images\/test\.23012\.png">/));
      assert.ok(changed.match(/<img src="\/\/images\/bar\.23012\.png">/));
      assert.ok(changed.match(/<img src="\/images\/misc\/test\.2a436\.png">/));

    });
  });
});

fails with the current version, but
runs with:
usemin.js, line 115, changed from

var type = this.target;

to

var type = options.type;

@stephanebachelier
Copy link
Collaborator

@veraee in usemin.js, I think it should be :

var type = options.type || this.target;

@veraee
Copy link

veraee commented Apr 9, 2015

I'm ok with that, but I think your issue is already adressed in lines 108--110

var options = this.options({
type: this.target
});

which already uses this.target as fallback if the user has not set options.type

@stephanebachelier
Copy link
Collaborator

@veraee you're right. Code review in a comment is not the best :)

@mhupman @veraee Would you mind open a PR against dev branch. I've some time later today so I might create the PR.

@stephanebachelier stephanebachelier self-assigned this Apr 13, 2015
@stephanebachelier
Copy link
Collaborator

I'm working on this PR. Will come back soon.

@stephanebachelier
Copy link
Collaborator

Closing in favor of #542

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants