octoper / statamic-inline-assets

Inline CSS or JS file for Statamic 3
MIT License
6 stars 7 forks source link

[BUG] BadMethodCallException Call to undefined method css. #4

Closed jmartsch closed 4 years ago

jmartsch commented 4 years ago

Description:

When I try to inline something (CSS in my case) an error is thrown:


<!--
--
  | Facade\Ignition\Exceptions\ViewException: Call to undefined method css. in file D:\htdocs\dotnetic\website\resources\views/layouts/main.antlers.html on line 0
  |  
  | #0 D:\htdocs\dotnetic\website\vendor\statamic\cms\src\Tags\Tags.php(127): ()
  | #1 [internal function]: Statamic\Tags\Tags->__call('css', Array)
  | #2 D:\htdocs\dotnetic\website\vendor\statamic\cms\src\View\Antlers\Engine.php(152): call_user_func(Array)
  | #3 [internal function]: Statamic\View\Antlers\Engine::renderTag(Object(Statamic\View\Antlers\Parser), 'inline_assets', Array, '', Array)
  | #4 D:\htdocs\dotnetic\website\vendor\statamic\cms\src\View\Antlers\Parser.php(575): call_user_func_array(Array, Array)
  | #5 D:\htdocs\dotnetic\website\vendor\statamic\cms\src\View\Antlers\Parser.php(176): Statamic\View\Antlers\Parser->parseCallbackTags('<!DOCTYPE html>...', Array)
  | #6 D:\htdocs\dotnetic\website\vendor\statamic\cms\src\View\Antlers\Parser.php(131): Statamic\View\Antlers\Parser->parse('<!DOCTYPE html>...', Array)
  | #7 D:\htdocs\dotnetic\website\vendor\statamic\cms\src\View\Antlers\Engine.php(89): Statamic\View\Antlers\Parser->parseView('D:\\htdocs\\dotne...', '<!DOCTYPE html>...', Array)
  | #8 D:\htdocs\dotnetic\website\vendor\laravel\framework\src\Illuminate\View\View.php(143): Statamic\View\Antlers\Engine->get('D:\\htdocs\\dotne...', Array)
  | #9 D:\htdocs\dotnetic\website\vendor\laravel\framework\src\Illuminate\View\View.php(126): Illuminate\View\View->getContents()
  | #10 D:\htdocs\dotnetic\website\vendor\laravel\framework\src\Illuminate\View\View.php(91): Illuminate\View\View->renderContents()
  | #11 D:\htdocs\dotnetic\website\vendor\statamic\cms\src\View\View.php(80): Illuminate\View\View->render()
  | #12 D:\htdocs\dotnetic\website\vendor\statamic\cms\src\Http\Responses\DataResponse.php(144): Statamic\View\View->render()
  | #13 D:\htdocs\dotnetic\website\vendor\statamic\cms\src\Http\Responses\DataResponse.php(45): Statamic\Http\Responses\DataResponse->contents()
  | #14 D:\htdocs\dotnetic\website\vendor\statamic\cms\src\Structures\Page.php(287): Statamic\Http\Responses\DataResponse->toResponse(Object(Illuminate\Http\Request))
  | #15 D:\htdocs\dotnetic\website\vendor\laravel\framework\src\Illuminate\Routing\Router.php(734): Statamic\Structures\Page->toResponse(Object(Illuminate\Http\Request))
  | #16 D:\htdocs\dotnetic\website\vendor\laravel\framework\src\Illuminate\Routing\Router.php(721): Illuminate\Routing\Router::toResponse(Object(Illuminate\Http\Request), Object(Statamic\Structures\Page))
  | #17 D:\htdocs\dotnetic\website\vendor\laravel\framework\src\Illuminate\Routing\Router.php(681): Illuminate\Routing\Router->prepareResponse(Object(Illuminate\Http\Request), Object(Statamic\Structures\Page))
  | #18 D:\htdocs\dotnetic\website\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(130): Illuminate\Routing\Router->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
  | #19 D:\htdocs\dotnetic\website\vendor\statamic\cms\src\StaticCaching\Middleware\Cache.php(29): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
  | #20 D:\htdocs\dotnetic\website\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(171): Statamic\StaticCaching\Middleware\Cache->handle(Object(Illuminate\Http\Request), Object(Closure))
  | #21 D:\htdocs\dotnetic\website\vendor\statamic\cms\src\Http\Middleware\Localize.php(22): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
  | #22 D:\htdocs\dotnetic\website\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(171): Statamic\Http\Middleware\Localize->handle(Object(Illuminate\Http\Request), Object(Closure))
  | #23 D:\htdocs\dotnetic\website\vendor\statamic\cms\src\Http\Middleware\StacheLock.php(29): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
  | #24 D:\htdocs\dotnetic\website\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(171): Statamic\Http\Middleware\StacheLock->handle(Object(Illuminate\Http\Request), Object(Closure))
  | #25 D:\htdocs\dotnetic\website\vendor\laravel\framework\src\Illuminate\Routing\Middleware\SubstituteBindings.php(41): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
  | #26 D:\htdocs\dotnetic\website\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(171): Illuminate\Routing\Middleware\SubstituteBindings->handle(Object(Illuminate\Http\Request), Object(Closure))
  | #27 D:\htdocs\dotnetic\website\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\VerifyCsrfToken.php(77): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
  | #28 D:\htdocs\dotnetic\website\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(171): Illuminate\Foundation\Http\Middleware\VerifyCsrfToken->handle(Object(Illuminate\Http\Request), Object(Closure))
  | #29 D:\htdocs\dotnetic\website\vendor\laravel\framework\src\Illuminate\View\Middleware\ShareErrorsFromSession.php(49): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
  | #30 D:\htdocs\dotnetic\website\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(171): Illuminate\View\Middleware\ShareErrorsFromSession->handle(Object(Illuminate\Http\Request), Object(Closure))
  | #31 D:\htdocs\dotnetic\website\vendor\laravel\framework\src\Illuminate\Session\Middleware\StartSession.php(56): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
  | #32 D:\htdocs\dotnetic\website\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(171): Illuminate\Session\Middleware\StartSession->handle(Object(Illuminate\Http\Request), Object(Closure))
  | #33 D:\htdocs\dotnetic\website\vendor\laravel\framework\src\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse.php(37): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
  | #34 D:\htdocs\dotnetic\website\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(171): Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle(Object(Illuminate\Http\Request), Object(Closure))
  | #35 D:\htdocs\dotnetic\website\vendor\laravel\framework\src\Illuminate\Cookie\Middleware\EncryptCookies.php(67): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
  | #36 D:\htdocs\dotnetic\website\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(171): Illuminate\Cookie\Middleware\EncryptCookies->handle(Object(Illuminate\Http\Request), Object(Closure))
  | #37 D:\htdocs\dotnetic\website\vendor\statamic\cms\src\StaticCaching\Middleware\Retrieve.php(34): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
  | #38 D:\htdocs\dotnetic\website\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(171): Statamic\StaticCaching\Middleware\Retrieve->handle(Object(Illuminate\Http\Request), Object(Closure))
  | #39 D:\htdocs\dotnetic\website\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(105): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
  | #40 D:\htdocs\dotnetic\website\vendor\laravel\framework\src\Illuminate\Routing\Router.php(683): Illuminate\Pipeline\Pipeline->then(Object(Closure))
  | #41 D:\htdocs\dotnetic\website\vendor\laravel\framework\src\Illuminate\Routing\Router.php(658): Illuminate\Routing\Router->runRouteWithinStack(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request))
  | #42 D:\htdocs\dotnetic\website\vendor\laravel\framework\src\Illuminate\Routing\Router.php(624): Illuminate\Routing\Router->runRoute(Object(Illuminate\Http\Request), Object(Illuminate\Routing\Route))
  | #43 D:\htdocs\dotnetic\website\vendor\laravel\framework\src\Illuminate\Routing\Router.php(613): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))
  | #44 D:\htdocs\dotnetic\website\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(170): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))
  | #45 D:\htdocs\dotnetic\website\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(130): Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}(Object(Illuminate\Http\Request))
  | #46 D:\htdocs\dotnetic\website\vendor\statamic\cms\src\Http\Middleware\CheckMultisite.php(14): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
  | #47 D:\htdocs\dotnetic\website\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(171): Statamic\Http\Middleware\CheckMultisite->handle(Object(Illuminate\Http\Request), Object(Closure))
  | #48 D:\htdocs\dotnetic\website\vendor\statamic\cms\src\Http\Middleware\PoweredByHeader.php(19): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
  | #49 D:\htdocs\dotnetic\website\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(171): Statamic\Http\Middleware\PoweredByHeader->handle(Object(Illuminate\Http\Request), Object(Closure))
  | #50 D:\htdocs\dotnetic\website\vendor\barryvdh\laravel-debugbar\src\Middleware\InjectDebugbar.php(67): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
  | #51 D:\htdocs\dotnetic\website\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(171): Barryvdh\Debugbar\Middleware\InjectDebugbar->handle(Object(Illuminate\Http\Request), Object(Closure))
  | #52 D:\htdocs\dotnetic\website\vendor\fideloper\proxy\src\TrustProxies.php(57): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
  | #53 D:\htdocs\dotnetic\website\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(171): Fideloper\Proxy\TrustProxies->handle(Object(Illuminate\Http\Request), Object(Closure))
  | #54 D:\htdocs\dotnetic\website\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\TransformsRequest.php(21): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
  | #55 D:\htdocs\dotnetic\website\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(171): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle(Object(Illuminate\Http\Request), Object(Closure))
  | #56 D:\htdocs\dotnetic\website\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\TransformsRequest.php(21): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
  | #57 D:\htdocs\dotnetic\website\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(171): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle(Object(Illuminate\Http\Request), Object(Closure))
  | #58 D:\htdocs\dotnetic\website\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\ValidatePostSize.php(27): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
  | #59 D:\htdocs\dotnetic\website\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(171): Illuminate\Foundation\Http\Middleware\ValidatePostSize->handle(Object(Illuminate\Http\Request), Object(Closure))
  | #60 D:\htdocs\dotnetic\website\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode.php(63): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
  | #61 D:\htdocs\dotnetic\website\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(171): Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode->handle(Object(Illuminate\Http\Request), Object(Closure))
  | #62 D:\htdocs\dotnetic\website\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(105): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
  | #63 D:\htdocs\dotnetic\website\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(145): Illuminate\Pipeline\Pipeline->then(Object(Closure))
  | #64 D:\htdocs\dotnetic\website\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(110): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request))
  | #65 D:\htdocs\dotnetic\website\public\index.php(55): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))
  | #66 {main}
  | -->

Steps To Reproduce:

Installed the addon via composer and inserted this in my main.antlers.html file:

  <style>
            {{ inline_assets:css src="css/site.css" }}
    </style>
jmartsch commented 4 years ago

The issue is, that the file InlineAssets.php is not the same as https://github.com/octoper/statamic-inline-assets/blob/master/src/InlineAssets.php

The file installed via composer looks like this:

<?php

namespace Octoper\InlineAssets;

use Statamic\Tags\Tags;

class InlineAssets extends Tags
{
    public function index()
    {
        $asset = public_path(
            $this->get(['src', 'path']),
        );

        return file_get_contents($asset);
    }
}
octoper commented 4 years ago

@jmartsch Have you updated to the latest version?

jmartsch commented 4 years ago

No, I just did an composer require octoper/statamic-inline-assets, which installed Version 1. Now I see that there are newer versions. I will try these instead.

octoper commented 4 years ago

I'm closing this issue for now, If the problem still exists feel free to re-open it.

ncla commented 3 years ago

@octoper

You need to setup Composer package publishing correctly. Running composer require octoper/statamic-inline-assets installs v1 and not the latest version.

➜  statamic git:(master) ✗ composer show octoper/statamic-inline-assets        
name     : octoper/statamic-inline-assets
descrip. : Inline CSS or JS file for Statamic 3
keywords : 
versions : * v1
type     : statamic-addon
license  : MIT License (MIT) (OSI approved) https://spdx.org/licenses/MIT.html#licenseText
homepage : 
source   : [git] https://github.com/octoper/statamic-inline-assets.git 6ca54778c140040d9b0bfd4ecbd237ea3c7beb36
dist     : [zip] https://api.github.com/repos/octoper/statamic-inline-assets/zipball/6ca54778c140040d9b0bfd4ecbd237ea3c7beb36 6ca54778c140040d9b0bfd4ecbd237ea3c7beb36
path     : /home/vagrant/statamic/vendor/octoper/statamic-inline-assets
names    : octoper/statamic-inline-assets

support
issues : https://github.com/octoper/statamic-inline-assets/issues
source : https://github.com/octoper/statamic-inline-assets/tree/master

autoload
psr-4
Octoper\InlineAssets\ => src

This is why OP and I are getting this error.

octoper commented 3 years ago

I have updated it, for me it's installing the latest version I don't know you are getting this error again and again 😬

ncla commented 3 years ago

Interestingly I can see that new versions have been published: https://repo.packagist.org/p2/octoper/statamic-inline-assets.json

I think it might be PHP version, you have specified PHP version of 7.4 or higher in composer requirements. My Homestead has PHP 7.3. Which is the same as OP.

➜  statamic git:(master) ✗ composer require octoper/statamic-inline-assets:^4.0.3

  [InvalidArgumentException]                                                                                                                              
  Package octoper/statamic-inline-assets at version ^4.0.3 has a PHP requirement incompatible with your PHP version, PHP extensions and Composer version  

So composer skips those versions and falls back to v1, I guess?

ncla commented 3 years ago

OK, updated to PHP 7.4 CLI (Homestead didn't have PHP 7.4 aliases mysteriously). Now without hard specifying a version, it goes for ^v4.0.

➜  statamic git:(master) ✗ composer require octoper/statamic-inline-assets

Using version ^4.0 for octoper/statamic-inline-assets
./composer.json has been updated
Running composer update octoper/statamic-inline-assets
Loading composer repositories with package information
Updating dependencies
Lock file operations: 3 installs, 0 updates, 0 removals
  - Locking matthiasmullie/minify (1.3.66)
  - Locking matthiasmullie/path-converter (1.1.3)
  - Locking octoper/statamic-inline-assets (4.0.3)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 3 installs, 0 updates, 0 removals
  - Installing matthiasmullie/path-converter (1.1.3): Extracting archive
  - Installing matthiasmullie/minify (1.3.66): Extracting archive
  - Installing octoper/statamic-inline-assets (4.0.3): Extracting archive

I guess updating README to include PHP requirement could helpful. Or lowering the PHP requirement, do we absolutely need 7.4 in this package?

Thanks.